How to calculate triangles?
#1

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
Reply
#2

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
Reply
#3

Thankyou YJIET and ******!

****** you're my Idol
Reply
#4

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.
Reply
#5

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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)