Problems with cos and sin in Android

Posted by bajen micke on Stack Overflow See other posts from Stack Overflow or by bajen micke
Published on 2012-03-26T23:16:30Z Indexed on 2012/03/26 23:30 UTC
Read the original article Hit count: 456

Filed under:
|
|

I have a problem with my code in Android. I am using this to moving a ball. If the degree is 90 it should move to the right, if the degree is 180 it should move down etc.

This is the code I have done.

int degrees=180;
int bollspeed=4;

bollX += bollspeed*Math.cos(Math.toRadians(degrees)); 
bollY += bollspeed*Math.sin(Math.toRadians(degrees));

The problem is that when the ball should move 90 degrees it moves 180, and when it should move 180 degrees it moves 270. I have tested all I could come to think... Can anyone see any error in my code or have a expanation I would be really glad. Thanks

© Stack Overflow or respective owner

Related posts about android

Related posts about sin