Class Sphere

  • All Implemented Interfaces:
    MeshMaker

    public class Sphere
    extends Model
    implements MeshMaker
    Create a wireframe model of a sphere centered at the origin.

    See https://en.wikipedia.org/wiki/Sphere

    A sphere of radius r is the surface of revolution generated by revolving a half-circle in the xy-plane with radius r and center (0,0,0) around the y-axis.

    Here are parametric equations for the right half-circle in the xy-plane with radius r and center (0,0,0), parameterized from the top down.

    
          x(phi) = r * sin(phi)  \
          y(phi) = r * cos(phi)   |-  0 <= phi <= PI
          z(phi) = 0             /
       
    Here is the 3D rotation matrix that rotates around the y-axis by theta radians, 0 <= theta <= 2*PI
    
          [ cos(theta)   0   sin(theta)]
          [     0        1       0     ]
          [-sin(theta)   0   cos(theta)]
       
    If we multiply the rotation matrix with the half-circle parameterization, we get a parameterization of the sphere.
    
          [ cos(theta)   0   sin(theta)]   [r * sin(phi)]
          [     0        1       0     ] * [r * cos(phi)]
          [-sin(theta)   0   cos(theta)]   [     0      ]
    
          = ( r * sin(phi) * cos(theta).    \
              r * cos(phi),                  |- 0<=theta<=2*PI,  0<=phi<=PI
             -r * sin(phi) * sin(theta) )   /
       
    See https://en.wikipedia.org/wiki/Sphere#Equations_in_three-dimensional_space
    See Also:
    SphereSector
    • Field Detail

      • r

        public final double r
      • n

        public final int n
      • k

        public final int k
    • Constructor Detail

      • Sphere

        public Sphere()
        Create a sphere of radius 1 centered at the origin.
      • Sphere

        public Sphere​(double r)
        Create a sphere of radius r centered at the origin.
        Parameters:
        r - radius of the sphere
      • Sphere

        public Sphere​(double r,
                      int n,
                      int k)
        Create a sphere of radius r centered at the origin.

        The last two parameters determine the number of half circles of longitude and the number of circles of latitude in the model.

        If there are k half circles of longitude, then each circle of latitude will have k line segments. If there are n circles of latitude, then each half circle of longitude will have n+1 line segments.

        There must be at least three half circles of longitude and at least one circle of latitude.

        Parameters:
        r - radius of the sphere
        n - number of circles of latitude
        k - number of half circles of longitude
        Throws:
        IllegalArgumentException - if n is less than 1
        IllegalArgumentException - if k is less than 3
    • Method Detail

      • remake

        public Sphere remake​(int n,
                             int k)
        Description copied from interface: MeshMaker
        Build an instance of the Model with new values for the number of lines of latitude and longitude while keeping all the other model parameters the same.
        Specified by:
        remake in interface MeshMaker
        Parameters:
        n - number of lines of latitude for the returned Model
        k - number of lines of longitude for the returned Model
        Returns:
        a new instance of the Model with the updated parameters