peng3d/model.py
def calcSphereCoordinates(pos,radius,rot):
    """
    Calculates the Cartesian coordinates from spherical coordinates.
    
    ``pos`` is a simple offset to offset the result with.
    
    ``radius`` is the radius of the input.
    
    ``rot`` is a 2-tuple of ``(azimuth,polar)`` angles.
    
    Angles are given in degrees. Most directions in this game use the same convention.
    
    The azimuth ranges from 0 to 360 degrees with 0 degrees pointing directly to the x-axis.
    
    The polar angle ranges from -90 to 90 with -90 degrees pointing straight down and 90 degrees straight up.
    
    A visualization of the angles required is given in the source code of this function.
    """
    # Input angles should be in degrees, as in the rest of the game
    # E.g. phi=inclination and theta=azimuth
    
    # phi is yrad
    #      Look from above         
    #(Z goes positive towards you) 
    #                              
    #            Y-  Z-            
    #            |  /              
    #            | / "far"         
    #            |/                
    #   X- ------+-------> X+      
    #           /| yrad |          
    #   "near" / |<-----+          
    #         /  |  "polar angle"  
    #        Z+  Y+                
    
    # theta is xrad
    #      Look from above         
    #(Z goes positive towards you) 
    #                              
    #            Y-  Z-            
    #            |  /              
    #            | / "far"         
    #            |/                
    #   X- ------+-------> X+      
    #           /| xrad |          
    #   "near" /<-------+          
    #         /  |  "azimuth angle"
    #        Z+  Y+                

    # Based on http://stackoverflow.com/questions/39647735/calculation-of-spherical-coordinates
    # https://en.wikipedia.org/wiki/Spherical_coordinate_system
    # http://stackoverflow.com/questions/25404613/converting-spherical-coordinates-to-cartesian?rq=1
    
    phi,theta = rot
    phi+=90 # very important, took me four days of head-scratching to figure out
    phi,theta = math.radians(phi),math.radians(theta)
    
    x = pos[0]+radius * math.sin(phi) * math.cos(theta)
    y = pos[1]+radius * math.sin(phi) * math.sin(theta)
    z = pos[2]+radius * math.cos(phi)
    return x,y,z
def calcSphereCoordinates(pos,radius,rot):
    """
    Calculates the Cartesian coordinates from spherical coordinates.
    
    ``pos`` is a simple offset to offset the result with.
    
    ``radius`` is the radius of the input.
    
    ``rot`` is a 2-tuple of ``(azimuth,polar)`` angles.
    
    Angles are given in degrees. Most directions in this game use the same convention.
    
    The azimuth ranges from 0 to 360 degrees with 0 degrees pointing directly to the x-axis.
    
    The polar angle ranges from -90 to 90 with -90 degrees pointing straight down and 90 degrees straight up.
    
    A visualization of the angles required is given in the source code of this function.
    """
    # Input angles should be in degrees, as in the rest of the game
    # E.g. phi=inclination and theta=azimuth
    
    # phi is yrad
    #      Look from above         
    #(Z goes positive towards you) 
    #                              
    #            Y-  Z-            
    #            |  /              
    #            | / "far"         
    #            |/                
    #   X- ------+-------> X+      
    #           /| yrad |          
    #   "near" / |<-----+          
    #         /  |  "polar angle"  
    #        Z+  Y+                
    
    # theta is xrad
    #      Look from above         
    #(Z goes positive towards you) 
    #                              
    #            Y-  Z-            
    #            |  /              
    #            | / "far"         
    #            |/                
    #   X- ------+-------> X+      
    #           /| xrad |          
    #   "near" /<-------+          
    #         /  |  "azimuth angle"
    #        Z+  Y+                

    # Based on http://stackoverflow.com/questions/39647735/calculation-of-spherical-coordinates
    # https://en.wikipedia.org/wiki/Spherical_coordinate_system
    # http://stackoverflow.com/questions/25404613/converting-spherical-coordinates-to-cartesian?rq=1
    
    phi,theta = rot
    phi+=90 # very important, took me four days of head-scratching to figure out
    phi,theta = math.radians(phi),math.radians(theta)
    
    x = pos[0]+radius * math.sin(phi) * math.cos(theta)
    y = pos[1]+radius * math.sin(phi) * math.sin(theta)
    z = pos[2]+radius * math.cos(phi)
    return x,y,z
Calculates the Cartesian coordinates from spherical coordinates.
    
    ``pos`` is a simple offset to offset the result with.
    
    ``radius`` is the radius of the input.
    
    ``rot`` is a 2-tuple of ``(azimuth,polar)`` angles.
    
    Angles are given in degrees. Most directions in this game use the same convention.
    
    The azimuth ranges from 0 to 360 degrees with 0 degrees pointing directly to the x-axis.
    
    The polar angle ranges from -90 to 90 with -90 degrees pointing straight down and 90 degrees straight up.
    
    A visualization of the angles required is given in the source code of this function.