We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
Page Index Toggle Pages: 1
acos (Read 340 times)
acos
Mar 31st, 2009, 6:34am
 
hi can anyone help me with this problem, i am trying to use the formula
cos(J) = (sq (p) + sq (q) - sq (n))- 2*p*q;

so inorder to get J i need to use an acos like this ;

float J = acos((sq (p) + sq (q) - sq (n))- 2*p*q);
however when i println it says NaN

does anyone know what im doing wrong?
Re: acos
Reply #1 - Mar 31st, 2009, 7:45am
 
I think you have to look into the fact if you input radians or degrees into the acos() function.

When reading the Reference about acos(), it is said:
"This function expects the values in the range of -1 to 1 and values are returned in the range 0 to PI (3.1415927)."

So the value of 'value' (in the code below) has to be within -1 and 1, for acos() to work. This depends on the values of p,q and n...

Code:

float value = radians ((sq(p) + sq(q) - sq(n)) - (2*p*q));
float J = acos( value );

Page Index Toggle Pages: 1