SA-MP Forums Archive
How to calculate triangles? - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: How to calculate triangles? (/showthread.php?tid=212112)



How to calculate triangles? - iMonk3y - 16.01.2011

Who doesn't love math? I need some simple examples on how to calculate angles, rises and bases in triangles wih sa-mp functions


No hurries


Re: How to calculate triangles? - Stylock - 16.01.2011

1) Angle:
pawn Код:
atan(3500.0 / 3500.0); //rise divided by base
To calculate the opposite angle, it would be the other way around (base divided by rise).


2) Base:
pawn Код:
//lets pretend the angle is 52.0
1100.0 * floattan(52.0, degrees);
There you go


Re: How to calculate triangles? - iMonk3y - 16.01.2011

Thankyou YJIET and ******!

****** you're my Idol


Re: How to calculate triangles? - Stylock - 16.01.2011

Quote:
Originally Posted by ******
Посмотреть сообщение
If you need a start point for searching, this is called trigonometry. Note that using tan as in your first example is likely more complex than you think because you have to take in to account the SIGNS of both sides, that's why there is an atan2 function (common and well documented on the internet).
I'm not any math genius and I only know basics about trigonometry, so I don't understand what you mean with "SIGNS". All I know about atan2 is that it's used to calculate angle between two points.


Re: How to calculate triangles? - Stylock - 17.01.2011

Ohh, now I see your point! In fact I made this little example to test it:
pawn Код:
new
    Float:x0 = 1500.0,
    Float:y0 = 1500.0;
new
    Float:x1 = -1500.0,
    Float:y1 = -1500.0;

printf("%f", atan(floatsqroot((x0 - x1) * (x0 - x1)) / floatsqroot((y0 - y1) * (y0 - y1))));
printf("%f", -atan2(x1 - x0, y1 - y0)); //afaik angles are inverted in sa-mp

/*
output:
 44.999996
135.000000
*/
So atan returns angle between hypotenuse and adjacent, like in triangle, and atan2 returns angle from 0 - 360 degrees.