Calculate angle from point to point - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Calculate angle from point to point (
/showthread.php?tid=299889)
Calculate angle from point to point -
Thomas. - 27.11.2011
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.
Re: Calculate angle from point to point -
Mauzen - 27.11.2011
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;
Re: Calculate angle from point to point -
Thomas. - 27.11.2011
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!
Re: Calculate angle from point to point -
RepzThat - 28.11.2011
You Should Be Called Thomas Edison HAHAA If You Get What I Mean ? :P