We are about to switch to a new forum software. Until then we have removed the registration on this forum.
The values I get out of the sine function are wrong, any ideas why?
float a = 180;
float b = sin(radians(a));
float c = sin(degrees(a));
println(b + " : " + c);
-8.742278E-8 : 0.5715942
a=0 (correct)
0 : 0
a=360 (what?!)
1.7484555E-7 : -0.93802774
a=2*PI (what!?)
0.10944261 : 0.9589157
Thanks!
Answers
converts a to degrees. but sin expects radians.
and if you're worried about a = 360
1.7484555E-7
read up on engineering notation - https://en.wikipedia.org/wiki/Engineering_notation
It seems like everything is fine wih the sin()-function. The problem might be that "PI" has only a limited number of digits, so the result of sin(0) and sin(2*PI) will never be equal, only close.
If you need higher precision you can use javas own Math.PI which is a double.
Ok, sin(PI) and sin(2PI) are just close to 0. but not exact. Thanks you guys.
there is a TWO_PI constant in processing as well
1.7484555E-7
But Processing's TWO_PI is a float, unlike Math.PI which is a double.
However, Processing's trigonometric functions want floats as input.