Spherical coordinates
From DmWiki
This article is a stub. You can help improve the article by expanding it.
| Table of contents |
Definition
Spherical coordinate are a means of descring a point in space by means of it distance from the origin and its direction. It uses radial (r) and two angular (θ,φ) coordinates.
If a point has spherical coordinates (r,θ,φ), then:
- r is the distance from the origin to the point.
- θ is the angle between the positive x-axis and the line from the origin to the point in the xy-plane (technically, it's the projection of this line into that plane).
- φ is the angle between the positive z-axis and the line from the origin to the point.
Note that some books and web sites will use θ where we say φ and vice versa. We have chosen this convention to be consistent with the use of θ in cylindrical coordinates.
This page would benefit from the use of an image. You can help improve the article by creating one.
Conversion from Cartesian coordinates
To convert Cartesian coordinates (x,y,z) to spherical coordinates, use the following relation:
Note that, as in the case of cylindrical coordinates, one must take care when computing the arctangent. The C++ function atan2(y, x) will give the correct answer for the arctangent of y / x.
Conversion from cylindrical coordinates
To convert from cylindrical coordinates (r,θ,z), simply keep the same r,θ values and then calculate:
.
Why is it useful?
For one thing, spherical coordinates are often used in cameras, where θ is interpreted as yaw and φ as pitch. Then you can use spherical coordinates to look left, right, up, and down, and convert the yaw and pitch values into a direction vector whenver you need it.
