Combining Directional Speed

Started by
2 comments, last by Hacktank 14 years ago
Hello, I am trying to combine directional speed. For example if a gameobject is has a speed of 10 and a direction of 90 degrees (i use radians but for the purposes of example simplicity im using degrees) and I try to apply downward speed (for example 15 speed, 270 degrees for example), this should end up with a speed of 5 at 270 degrees. But how would i actually calculate this? And on a side-note how would i go from speed/direction to x and y speed and the other way around? Thank You. [Edited by - Hacktank on April 16, 2010 5:17:10 PM]

Advertisement
You add vectors.

Vectors can be represented in polar coordinates or rectangular coordinates.

Your representation (angle,radius) is polar coordinates. You can use the law of cosines to add vectors in that representation if you choose, but it is much,much easier to convert the representation to rectangular (x,y) and add them in that representation.

To do the conversion, given (angle,radius) = (theta,phi)

x=radius*cos(theta);
y=radius*sin(theta);

the opposite conversion is
radius=sqrt(x*x+y*y);
theta=atan2(y,x);


to add two vectors in rectangular,
x=x1+x2;
y=y1+y2;
You add vectors.

Vectors can be represented in polar coordinates or rectangular coordinates.

Your representation (angle,radius) is polar coordinates. You can use the law of cosines to add vectors in that representation if you choose, but it is much,much easier to convert the representation to rectangular (x,y) and add them in that representation.

To do the conversion, given (angle,radius) = (theta,phi)

x=radius*cos(theta);
y=radius*sin(theta);

the opposite conversion is
radius=sqrt(x*x+y*y);
theta=atan2(y,x);


to add two vectors in rectangular,
x=x1+x2;
y=y1+y2;
Thank you, very thorough and helpful answer.

This topic is closed to new replies.

Advertisement