Subject: Program to convert spherical polar coordinates to XYZ coordinates

From: "Ya-Jun Zheng" <[email-masked]>
Date: Fri, 16 Nov 2001 08:20:51 -0500

Hi,

I am looking for a simple program or script to convert spherical polar
coordinates of a molecule to either XYZ or internal coordinates. Any help
or suggestions will be appreciated.  Thanks.     Yajun

---

From: "Armin M. Sobhani" <[email-masked]>
Date: Fri, 16 Nov 2001 22:40:01 +0330

Dear Zheng,

Here is a simple algorithm in C semantics that simply does the trick in 
both ways. It is very easy to rewrite them as two separate functions:

Polar coordinate (latitude, longitude, distance) to Euclidean coordinate 
(X, Y, Z):

         x = cos(latitude) * sin(longitude);
         y = sin(latitude);
         z = cos(latitude) * cos(longitude);

Euclidean coordinate (X, Y, Z) to Polar coordinate (latitude, longitude, 
distance):

         distance  = sqrt(x*x + y*y + z*z);
         x        /= distance;
         y        /= distance;
         z        /= distance;
         xz_dist   = sqrt(x*x + z*z);
         latitude  = atan2(xz_dist, y) * RADIANS;
         longitude = atan2(x, z)       * RADIANS;

Good luck,

Armin