Targeting point

I have to do some calculations.

In short, the math exercise is :

Double xCurrentPt, yCurrentPt;
Double xTargetPt, yTargetPt;
Double angle;

Suppose a man is standing at position xCurrentPt, yCurrentPt and with angle "Angle". Now he want to move to position xTargetPt, yTargetPt. Before walking he must rotate himself to a proper angle value. He'll continue to walk with his speed 'fSpeed' until he's reached the Target position (xTargetPt, yTargetPt)

The problem is I can't get the new right angle when the target has been changed.
Eg :

xCurrentPt = 200;
yCurrentPt = 250;
Angle = 72ยบ

Target :
xTargetPt : 125;
yTargetPt : 865;
Angle : ???????????

How to get the angle (or radian) between the current point and the target point? What the function is used to do this? Help please...
Last edited on
This might help you:

As the length of the triangle sides you should use the x and y distance of the man to the target. For example:

double horizontalLine = xTargetPt - xCurrentPt;
double verticalLine = yTargetPt - yCurrentPt;

Now all you need to do is to calculate the angle between those two lines (think of it as a triangle, which means, connect the end of the horizontalLine with the end of the verticalLine). It probably helps to make a sketch.

By the way: You get all the trigonometric functions you need through the cmath ( ) library.
Last edited on
Topic archived. No new replies allowed.