[PD] zexy 1.1 bugfix (was: cart2sph)
Robert Figura
rfigura at aubergine.zwischengesicht.de
Fri Nov 22 12:42:32 CET 2002
On 21 Nov, bbogart at 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(Z, sqrt(X*X+Y*Y)); /* THETA */
---
> 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
- Robert Figura
--
/* mandlsig.c v0.23 (c) by Robert Figura <rfigura at metabit.com> */
I=1702;float O,o,i;main(l){for(;I--;putchar("oO .,\nm>cot.bitamea\
@urigrf <raguFit erobR"[I%74?I>837&874>I?I^833:l%5:5]))for(O=o=l=
0;O*O+o*o<(16^l++);o=2*O*o+I/74/11.-1,O=i)i=O*O-o*o+I%74*.04-2.2;}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 232 bytes
Desc: not available
URL: <http://lists.puredata.info/pipermail/pd-list/attachments/20021122/c55b4f88/attachment.pgp>
More information about the Pd-list
mailing list