Avatar of Poolcorp
Poolcorp
Flag 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!
Math / Science

Avatar of undefined
Last Comment
Poolcorp

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
phoffric

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
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
ozo

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
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?
phoffric

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?
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
Poolcorp

ASKER
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.
phoffric

>> 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
Poolcorp

ASKER
Thanks guys that was exactly what I needed!
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.