Handout 25

Spherical Coordinates


The convential way of describing spherical coordinates is as follows:

In PovRay, since we're using a left-handed coordinate system, we have the following notation:

Using this notation, we can convert spherical to Cartesian coordinates by (using PovRay functions):

x = rho * sin(radians(theta)) * sin(radians(phi));
y = rho * cos(radians(theta));     
z = rho * sin(radians(theta)) * cos(radians(phi));

Example

In the following example, we use spherical coordinates to "hover" around a moving object. The starting and ending frames are shown below:

The code of interest:

#include "colors.inc"
                                                  
#declare rho = 15;
#declare theta = 45;
#declare phi = 180 + clock * 360;                                                  
                                                  
#declare zCord=rho * sin(radians(theta)) * cos(radians(phi));
#declare xCord=rho * sin(radians(theta)) * sin(radians(phi));
#declare yCord=rho * cos(radians(theta));     

camera {location <xCord, yCord, zCord + clock * 30> 
        look_at <0,0,clock * 30> 
}

light_source {<0,100,0> rgb <1.0, 1.0, 1.0>}            
light_source {<0,-100,0> rgb <1.0, 1.0, 1.0>}    
light_source {<-100,100,100> rgb <1.0, 1.0, 1.0>}            
light_source {<xCord, yCord, zCord + clock * 30> rgb <1.0, 1.0, 1.0>}    

box {
    <1, 1, 1>  // Near lower left corner
    <-1, 0, -1>   // Far upper right corner
    texture {
        pigment { color Yellow }
    }
    scale <1,1,1>
    translate <0,0,clock * 30>
 }

The Code