Calculate angle from point to point
#1

Hi,

I'm looking for a way/formula to calculate the angle from a point to another point, relative to the angle of the central point of view.
The coordinates of both points are given.

To clarify what I mean I've made an example image.
In this picture the central point's angle is 0° and the object is at 90° from the central point of view.




In this picture the angle of the central point has changed, but both points have not moved.
The object is now at 45° from the central point of view.



How could I achieve this?

Thanks in advance.
Reply
#2

Its some trigonometry combined with patience when finding out the right system for sa-mp. I got this somewhere in some script, it should do the job.

pawn Код:
// arctan with x/y offset of the points
new Float:angle = atan2(x1 - x2, y1 - y2);
// angle of point 1
angle += rot1;
// correction
if(angle > 360.0) angle -= 360.0;
Reply
#3

I had been playing around with trigonometric functions, and looking at your code I have just been thinking way too difficult.

Thank you, it's working like a charm!
Reply
#4

You Should Be Called Thomas Edison HAHAA If You Get What I Mean ? :P
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)