Link to home
Start Free TrialLog in
Avatar of Poolcorp
PoolcorpFlag for United States of America

asked on

Calcualting angle to Destination Point given origin point and current rotation

My geometry and trig are rather rusty, I am working on a project where I am given a destination point in a cartesian coordinate system (IE X: 0, Y: 0) and the objects current rotation and position (or point). I want to be able to find out what rotation or angle my object needs to be to line up with said destination point.

So for example lets say my objects start out a 0,0 with a rotation of 0. The destination I am given is 3, 4. What math would I need to find the angle i need to set my  object to to head in a straight line to that path?

Thanks!
ASKER CERTIFIED SOLUTION
Avatar of phoffric
phoffric

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of phoffric
phoffric

But if you are trying to animate the movement, then you do not need to know the angle.
The slope is 4/3 = 1.33333...

So, if you want to move the point in increments of, say, 0.1 units in x, the the corresponding y movement would be 0.1 * 4/3 = 0.1333 units in y.

Or if you want ot move in increments of, say, 0.03 units in x, then the point will move 0.04 units in y.
As long as the ratio of deltaY/deltaX  = 4/3, then your movements will go in a straight line to (4,3).

That's the simple explanation. In practice, you have to concern yourself with floating point errors.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Poolcorp

ASKER

I think its pretty close to what  I need,  but what if my object is at -2, 4 going to 5,-3
and he is already rotated at angle of 23 degrees?
deltaY/deltaX = (-3 - 4)/(5 - -2) = -7/7 = -1
slope = -1
angle = -45 degrees
If moving in frames, then for every 0.1 units in x, there is a corresponding -0.1 units in y.

Are you planning on rotating while moving? What do you want to do w.r.t. rotation?
I guess it might help a bit if I explain what i am doing =).

For a class I am in  I am working with the Player/Stage robot simulation environment. What I am trying to find out is what do I need to rotate to in order to move forward in a straight line from my current point to my waypoint I have set up. I can find out at any given moment the X and Y coordinates and the yaw of the robot. There really inst a way to specify moving in certain amounts of units in any direction just an angle or rotation and speed of movement.
>> speed of movement
If you know the time between starting point A, and ending point B, then you can compute the translation velocity vector, V. So, if you know V and you know your time increment, dt, then your incremental positional vector dP = V*dt.

On rotation, if you know your start and stop angles, then you know your delta angle, DA. You know the time, T, it takes to get between A and B. And you know your time increment, dt. So, in each time increment, why can't you just change the angle dA by the amount DA * (dt/T)?

Here are a number of links that you probably need to be familiar with (if not already).

Starts off with simpler 2D rotation and moves to 3D rotation:
http://en.wikipedia.org/wiki/Rotation_matrix

Here is an extensive link on 3D modeling:
http://www.euclideanspace.com/threed/index.htm
And because it is not easy to find in this list, here is the drill down to rotation:
http://www.euclideanspace.com/maths/algebra/matrix/orthogonal/rotation/index.htm

On 3D rotation:
http://www.fastgraph.com/makegames/3drotation/
http://www.siggraph.org/education/materials/HyperGraph/modeling/mod_tran/3drota.htm
Thanks guys that was exactly what I needed!