Class Torus

  • All Implemented Interfaces:
    MeshMaker

    public class Torus
    extends Model
    implements MeshMaker
    Create a wireframe model of a torus.

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

    This torus is the surface of revolution generated by revolving the circle in the xy-plane with radius r2 and center (r1,0,0) around the y-axis. We are assuming that r1 > r2.

    Here are parametric equations for the circle in the xy-plane with radius r2 and center (r1,0,0) and parameterized starting from the top, with parameter 0 <= phi <= 2*PI.

    
          x(phi) = r1 + r2 * sin(phi)
          y(phi) =      r2 * cos(phi)
          z(phi) = 0
       
    Here is the 3D rotation matrix that rotates around the y-axis by theta radians with 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 circle parameterization, we get a parameterization of the torus.
    
          [ cos(theta)   0   sin(theta)]   [r1 + r2 * sin(phi)]
          [     0        1       0     ] * [     r2 * cos(phi)]
          [-sin(theta)   0   cos(theta)]   [        0         ]
    
          = ( r1*cos(theta) + r2*cos(theta)*sin(phi).
              r2*cos(phi),
             -r1*sin(theta) - r2*sin(theta)*sin(phi) )
    
          = ( (r1 + r2*sin(phi)) * cos(theta),
                    r2*cos(phi),
             -(r1 + r2*sin(phi)) * sin(theta) )
       
    See https://en.wikipedia.org/wiki/Torus#Geometry
    See Also:
    TorusSector
    • Field Detail

      • r1

        public final double r1
      • r2

        public final double r2
      • n

        public final int n
      • k

        public final int k
    • Constructor Detail

      • Torus

        public Torus()
        Create a torus with a circle of revolution with radius 3/4 and a cross section circle (circle of longitude) with radius 1/4.
      • Torus

        public Torus​(double r1,
                     double r2)
        Create a torus with a circle of revolution with radius r1 and a cross section circle (circle of longitude) with radius r2.
        Parameters:
        r1 - radius of the circle of revolution
        r2 - radius of the cross section circle (circle of longitude)
      • Torus

        public Torus​(double r1,
                     double r2,
                     int n,
                     int k)
        Create a torus with a circle of revolution with radius r1 and a cross section circle (circle of longitude) with radius r2.

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

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

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

        Parameters:
        r1 - radius of the circle of revolution
        r2 - radius of the cross section circle (circle of longitude)
        n - number of circles of latitude
        k - number of circles of longitude
        Throws:
        IllegalArgumentException - if n is less than 3
        IllegalArgumentException - if k is less than 3
    • Method Detail

      • remake

        public Torus 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