This site requires JavaScript, please enable it in your browser!
Greenfoot back
kiarocks
kiarocks wrote ...

2012/8/13

Getting dx and dy from rotation and speed.

kiarocks kiarocks

2012/8/13

#
How would I go about getting the dx and dy from rotation and movement?
danpost danpost

2012/8/13

#
Do not count on it, but it would seem that: dx = movement * cos(rotation) * cos(rotation) dy = movement * sin(rotation) * sin(rotation) At least, it makes some sense to me.
lux lux

2012/8/14

#
what exactly do you mean by movement? If movement is the distance which the object moved then: dx = distance * sin; dy = distance * cos; And if you really mean speed then it depends on how long your object moved.
SPower SPower

2012/8/14

#
@lux this: dx = distance * sin; is a bit nonsence. Sin isn't just a number: sin is a result of a calculation with a number, like danpost was saying. And with movement, he means the amount of pixels/cells/whatever you will move facing your direction.
lux lux

2012/8/14

#
@SPower: tought it was obvious that a trigonometric function needs an angle as an argument ... maybe I should have been more accurate. If movement is the distance my version should be correct: double dx = distance * Math.sin(angle); double dy = distance * Math.cos(angle);
kiarocks kiarocks

2012/8/14

#
Cool, I'll see what works.
danpost danpost

2012/8/14

#
It would seem that dy would use the 'sin' function and dx would use the 'cos' function, since when the angle is zero, the y offset is zero and the x offset is the distance moved (or the radius). And as the rotation increases, dy increases from zero, and dx decreases from the movement amount.
lux lux

2012/8/15

#
Yes you are right! I answered that out of my head and mixed opposite and adjacent. @danpost: thank you for correcting ^^ @kiarocks: finally this should work :
double dx = distance * Math.cos(angle);
double dy = distance * Math.sin(angle);
kiarocks kiarocks

2012/8/15

#
Thanks, that worked.
You need to login to post a reply.