On 21 Nov, bbogart@ryerson.ca wrote:
I'm very confused by the values given by cart2sph in zexy 1.1. They conflict with my original expr based equation.
So If I have x=5, y=5 and z=5
[...]
I'm using this equation:
x^2+y^2+z^2=r^2 theta=cos^-1(z/r) phi=tan^-1(y/x)
From the zexy source I see:
x->new_coord[0]=sqrtf(X*X+Y*Y+Z*Z); /* R */ x->new_coord[1]=atan2f(Y, X); /* PHI */ x->new_coord[2]=atan2f(Z, sqrt(X*X+Y*Y)); /* THETA */
PHI is all right, but if: atan2f(a,b) := atan(a/b) then THETA is wrong (wrong parameter order), corrected:
$ diff zexy/src/z_coordinates.c ./z_coordinates.c 218c218
x->new_coord[2]=atan2f(sqrt(X*X+Y*Y), Z); /* THETA */
Because of this identity: atan( sqrt( x*x + y*y ) / z ) == acos( z / r ). Your formula also is correct. Lets see what my calculator says:
$ echo 'a( 5 / 5 )' | bc -l .78539816339744830961
echo 'a( sqrt( 5*5 + 5*5 ) / 5 )' | bc -l .95531661812450927816
As to be expected. Any veto?
IOhannes? zexy 1.2? Or is it free on CVS? (ask first ;^)
BTW: atan2(a,b) is a standard c function? Makes sense in case b is zero. So i had had no need to implement it myself?
HTH