For a programming project, I'm using a spherical coordinate system on the basis that it would be easier to handle. However, having programmed in a lot of different structures, I found that the Maths textbook I was relying on, while having a section on spherical coordinates, was limited to two pages on the topic.

So far, Google has been no help. It might be that I'm phrasing my searches incorrectly, but I've yet to find anything I can understand.

Can someone explain, or point me to a page that can explain, translation of points using spherical triples (ie. Translate point (r, θ, φ) by (d, θ, φ), where d is the distance from the point's current placement and the angles are standard).

~Watercleave

## Help with spherical coordinates

**Moderators:** gmalivuk, Moderators General, Prelates

- skeptical scientist
- closed-minded spiritualist
**Posts:**6142**Joined:**Tue Nov 28, 2006 6:09 am UTC**Location:**San Francisco

### Re: Help with spherical coordinates

This is adding two vectors. By far the easiest way to do this with spherical coordinates is to convert from spherical to rectangular, add the vectors, and convert back to spherical. Spherical coordinates are great for dealing with certain things, but rectangular coordinates are much better for others, and adding vectors is one of them.

I'm looking forward to the day when the SNES emulator on my computer works by emulating the elementary particles in an actual, physical box with Nintendo stamped on the side.

"With math, all things are possible." —Rebecca Watson

"With math, all things are possible." —Rebecca Watson

### Re: Help with spherical coordinates

In this figure, you see that [math]z_E = \rho \cos \phi[/math] and that the length of line segment [imath]z_E E[/imath] is equal to [imath]\rho \sin \phi[/imath].

Looking in the xOy-plane at the bottom you find the projection of this line segment, which has the same length.

Multiplying this by [imath]\cos \theta[/imath], you find [math]x_E = \rho \sin \phi \cos \theta[/math]

Similarly, multiplying it by [imath]\sin \theta[/imath], you find [math]y_E = \rho \sin \phi \sin \theta[/math]

So we have now expressed [imath]x[/imath], [imath]y[/imath] and [imath]z[/imath] in terms of [imath]\rho[/imath], [imath]\theta[/imath] and [imath]\phi[/imath].

If you also want to do it the other way round, let me show you a fragment of Java code to accomplish this:

Code: Select all

` rho = Math.sqrt(xE * xE + yE * yE + zE * zE);`

theta = Math.atan2(yE, xE);

phi = Math.acos(zE/rho);

(It would have been more usual to denote the point in question by P instead of E, but I had this picture available on my computer as an illustration in a book of mine on Computer Graphics for Java Programmers, in which I used the letter E for the eye of the viewer of a 3D object.)

### Who is online

Users browsing this forum: Bing [Bot] and 14 guests