3.11 Spherical Coordinates
As we can see in this figure, a point in spherical coordinates is characterized by the radius \(\rho\), by an angle \(\phi\) (called longitude or azimuth angle) between the projection of the radius onto the \(XY\) plane and the \(X\) axis, and, finally, by the angle \(\psi\) (called colatitude, zenith or polar angle) formed by the radius and the \(Z\) axis. Colatitude is the complementary angle to the latitude, i.e., the difference between \(\frac{\pi}{2}\) and the latitude.
Spherical Coordinates.
A point in spherical coordinates \((\rho, \phi, \psi)\), is represented in rectangular coordinates as \[(\rho \sin \psi \cos \phi, \rho \sin \psi \sin \phi, \rho \cos \psi)\]
Likewise, a point in rectangular coordinates \((x,y,z)\) translates to spherical coordinates as \[(\sqrt{x^2+y^2+z^2},\arctan\frac{y}{x}, \arctan\frac{\sqrt{x^2+y^2}}{z})\]
As it happens with cylindrical coordinates, the constructor of spherical coordinates sph is already predefined in Khepri, but it is not difficult to deduce its definition:
sph(rho, phi, psi) =
xyz(rho*sin(psi)*cos(phi), rho*sin(psi)*sin(phi), rho*cos(psi))
A similar definition is also available for the function vsph, which creates vectors in spherical coordinates.
3.11.1 Exercises 19
3.11.1.1 Question 55
Define the selectors sph_rho, sph_phi, and sph_psi that return, respectively, the components \(\rho\), \(\phi\) and \(\psi\) of a point built with the constructor sph.
3.11.1.2 Question 56
The Mohawk hairstyle was widely used during the punk period. It is defined by styling the hair in the shape of a crest, as schematized below:
Define the function mohawk, with parameters \(P\), \(r\), \(l\), \(\phi\) and \(\Delta_\psi\), which creates 9 cones of length \(l\) and base radius \(r\), all centered at the point \(P\), leaning at an angle \(\Delta_\psi\) between them and placed along a plane with an angle \(\phi\) with the \(XZ\) plane.
The examples presented in the previous figure resulted from the following expressions:
mohawk(xyz(0, 0, 0), 1.0, 10, pi/2, pi/6)
mohawk(xyz(0, 15, 0), 0.5, 15, pi/3, pi/9)
mohawk(xyz(0, 30, 0), 1.5, 6, pi/4, pi/8)