16.01.2011, 16:19
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
No hurries
atan(3500.0 / 3500.0); //rise divided by base
//lets pretend the angle is 52.0
1100.0 * floattan(52.0, degrees);
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).
|
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
*/