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?
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.
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?
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).
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.