001/*
002
003*/
004
005package renderer.models;
006import  renderer.scene.*;
007
008/**
009   Create an x and y axis in the xy-plane, along with "tick marks".
010*/
011public class Axes2D extends Model
012{
013   /**
014      Create an x and y axis from -1 to +1 on each axis.
015   */
016   public Axes2D( )
017   {
018      this(-1, 1, -1, 1, 0.0, 5, 5);
019   }
020
021
022   /**
023      Create an x-axis from {@code xMin} to {@code xMax}
024      and a y-axis from {@code yMin} to {@code yMax}.
025
026      @param xMin    left end point for the x-axis
027      @param xMax    right end point for the x-axis
028      @param yMin    bottom end point for the y-axis
029      @param yMax    top end point for the y-axis
030      @param xMarks  number of evenly spaced tick marks on the x-axis
031      @param yMarks  number of evenly spaced tick marks on the y-axis
032   */
033   public Axes2D(double xMin, double xMax, double yMin, double yMax,
034                 int xMarks, int yMarks)
035   {
036      this(xMin, xMax, yMin, yMax, 0.0, xMarks, yMarks);
037   }
038
039
040   /**
041      Create an x-axis from {@code xMin} to {@code xMax}
042      and a y-axis from {@code yMin} to {@code yMax}.
043   <p>
044      The {@code z} parameter is so that we can put the axis just above
045      or just below the xy-plane (say {@code z=0.01} or {@code z=-0.01}).
046      This way, the axes can be just in front of or just behind whatever
047      is being drawn in the xy-plane.
048
049      @param xMin    left end point for the x-axis
050      @param xMax    right end point for the x-axis
051      @param yMin    bottom end point for the y-axis
052      @param yMax    top end point for the y-axis
053      @param z       offset of the axes away from the xy-plane
054      @param xMarks  number of evenly spaced tick marks on the x-axis
055      @param yMarks  number of evenly spaced tick marks on the y-axis
056   */
057   public Axes2D(double xMin, double xMax, double yMin, double yMax,
058                 double z, int xMarks, int yMarks)
059   {
060      super();
061
062       // x-axis
063      addLineSegment(new LineSegment(new Vertex(xMin, 0, z),
064                                     new Vertex(xMax, 0, z)));
065
066       // y-axis
067      addLineSegment(new LineSegment(new Vertex(0, yMin, z),
068                                     new Vertex(0, yMax, z)));
069
070       // Put evenly spaced tick marks on the x-axis.
071      double xDelta = (xMax - xMin)/xMarks;
072      double yDelta = (yMax - yMin)/50;
073      for (double x = xMin; x <= xMax; x += xDelta)
074      {
075         addLineSegment(new LineSegment(new Vertex(x,  yDelta/2, z),
076                                        new Vertex(x, -yDelta/2, z)));
077      }
078
079       // Put evenly spaced tick marks on the y-axis.
080      yDelta = (yMax - yMin)/yMarks;
081      xDelta = (xMax - xMin)/50;
082      for (double y = yMin; y <= yMax; y += yDelta)
083      {
084         addLineSegment(new LineSegment(new Vertex( xDelta/2, y, z),
085                                        new Vertex(-xDelta/2, y, z)));
086      }
087   }
088}//Axes2D