001/*
002
003*/
004
005package renderer.models;
006import  renderer.scene.*;
007
008/**
009   Create a wireframe model of a sector of a ring (an annulus)
010   in the xy-plane centered at the origin.
011<p>
012   See <a href="https://en.wikipedia.org/wiki/Annulus_(mathematics)" target="_top">
013                https://en.wikipedia.org/wiki/Annulus_(mathematics)</a>
014<p>
015   See <a href="https://en.wikipedia.org/wiki/Circular_sector" target="_top">
016                https://en.wikipedia.org/wiki/Circular_sector</a>
017
018   @see Ring
019*/
020public class RingSector extends Model
021{
022   /**
023      Create half a ring (annulus) in the xy-plane
024      with outer radius 1, inner radius 0.33, with 7
025      spokes coming out of the center, and with 5
026      concentric circles.
027   */
028   public RingSector( )
029   {
030      this(1.0, 0.33, 0, Math.PI, 5, 7);
031   }
032
033
034   /**
035      Create a sector of a ring (annulus) in the xy-plane
036      with outer radius {@code r1}, inner radius {@code r2},
037      with {@code k} spokes coming out of the center, and
038      with {@code n} concentric circles.
039   <p>
040      Notice that if there are {@code k} spokes, then each
041      (partial) circle around the center will have {@code k-1}
042      line segments. If there are {@code n} concentric circles
043      around the center, then each spoke will have {@code n-1}
044      line segments.
045   <p>
046      There must be at least four spokes and at least two concentric circle.
047
048      @param r1      outer radius of the ring
049      @param r2      inner radius of the ring
050      @param theta1  beginning angle of the sector
051      @param theta2  ending angle of the sector
052      @param n       number of concentric circles
053      @param k       number of spokes in the ring
054   */
055   public RingSector(double r1, double r2,
056                     double theta1, double theta2,
057                     int n, int k)
058   {
059      super();
060
061      if (n < 2) n = 2;
062      if (k < 4) k = 4;
063
064      // Create the rings's geometry.
065
066      double deltaR = (r1 - r2) / (n - 1);
067      double deltaTheta = (theta2 - theta1) / (k - 1);
068
069      // An array of vertices to be used to create line segments.
070      Vertex[][] v = new Vertex[n][k];
071
072      // Create all the vertices.
073      for (int j = 0; j < k; j++) // choose a spoke (an angle)
074      {
075         double c = Math.cos(theta1 + j * deltaTheta);
076         double s = Math.sin(theta1 + j * deltaTheta);
077         for (int i = 0; i < n; i++) // move along the spoke
078         {
079            double ri = r2 + i * deltaR;
080            v[i][j] = new Vertex(ri * c,
081                                 ri * s,
082                                 0);
083         }
084      }
085
086      // Create line segments around each concentric ring.
087      for (int i = 0; i < n; i++)  // choose a ring
088      {
089         for (int j = 0; j < k - 1; j++)
090         {
091            addLineSegment(new LineSegment(new Vertex(v[i][j]),
092                                           new Vertex(v[i][j+1])));
093         }
094      }
095
096      // Create the spokes.connecting the inner circle to the outer circle.
097      for (int j = 0; j < k; j++) // choose a spoke
098      {
099         for (int i = 0; i < n - 1; i++)
100         {
101            addLineSegment(new LineSegment(new Vertex(v[i][j]),
102                                           new Vertex(v[i+1][j])));
103         }
104      }
105   }
106}//RingSector