I was trying to calculate the value of an angle of a right triangle. The sides were the opposite, and the hypotenuse, which happens to be adjacent to the angle as well. One code written in Java used atan2 to get the angle. When I used atan2 in C, I got differing values. The only way for me to get the correct values was to use asin.
Here is the code snippet in C:
for(i = 0; i < n; i++)
{
m = sqrt( (x - l[i].x) * (x - l[i].x) + (y * y) );
dist = abs(x - l[i].x);
ang = asin(dist/m) * 180.0 / 3.14159265;
if(ang <= (l[i].a + .01))
total += (double) l[i].I/(m*m);
}
Here is the code snippet in Java:
for (j = 0; j < n; j++)
{
d = Math.sqrt( (xs - lights[j]) * (xs - lights[j]) + (ys * ys) );
w = Math.abs(xs - lights[j]);
ang = Math.atan2(w, ys) * 180.0 / 3.14159265;
if (ang <= angles[j] + 0.01)
{
total += (double ) intensities[j] / (d * d);
}
}
Can anyone shed some light on this issue?
opposite/hypotenuse = sine, hence one should use asin to get the angle.