Class Grid

java.lang.Object
com.github.gbenroscience.math.graph.Grid

public class Grid extends Object
Author:
JIBOYE Oluwagbemiro Olaoluwa
  • Field Details

  • Constructor Details

    • Grid

      public Grid(String function, boolean showGridLines, boolean labelAxis, int gridSize, GraphColor gridColor, GraphColor majorAxesColor, GraphColor tickColor, GraphColor plotColor, int majorTickLength, int minorTickLength, double lowerXLimit, double upperXLimit, double xStep, double yStep, GraphFont font, boolean useTurbo, AbstractView component)
      Parameters:
      function - The function to be plotted on this Grid object. It may be an algebraic one or a geometric or vertices based one. The algebraic one is entered as y=f(x)..while the geometric one is entered in the form: [2,3,4,5]:[-90,3,15,9]
      showGridLines - sets whether the grid lines will be visible or not.
      labelAxis -
      gridSize - determine the size of the small boxes that make up the grid.
      gridColor - The color of the grid.
      majorAxesColor - The color of the major axes, x and y.
      tickColor - The color of the ticks used to mark off the coordinate axes.
      plotColor -
      majorTickLength - The length of the longer ticks used to mark off the graph.
      minorTickLength - The length of the shorter ticks used to mark off the graph
      lowerXLimit - The lower value of x up to which the graph will be plotted.
      upperXLimit - The upper value of x up to which the graph will be plotted.
      xStep - The resolution of the graph along x.
      yStep -
      font -
      useTurbo -
      component - The component on which this grid will be laid.
    • Grid

      public Grid(String function, boolean showGridLines, boolean labelAxis, int gridSize, GraphColor gridColor, GraphColor majorAxesColor, GraphColor tickColor, GraphColor plotColor, int majorTickLength, int minorTickLength, double lowerXLimit, double upperXLimit, double xStep, double yStep, GraphFont font, AbstractView component)
  • Method Details

    • validateMaxIterations

      public void validateMaxIterations()
      validates the xStep attribute. It checks if the number of iterations is not greater.
    • setComponent

      public void setComponent(AbstractView component)
    • getComponent

      public AbstractView getComponent()
    • setDRG

      public void setDRG(int DRG)
    • getDRG

      public int getDRG()
    • getHorizontalAxisLabel

      public Variable getHorizontalAxisLabel()
    • setHorizontalAxisLabel

      public void setHorizontalAxisLabel(Variable horizontalAxisLabel)
    • getVerticalAxisLabel

      public Variable getVerticalAxisLabel()
    • setVerticalAxisLabel

      public void setVerticalAxisLabel(Variable verticalAxisLabel)
    • setPlotColor

      public void setPlotColor(GraphColor plotColor)
    • setDefaultScale

      public void setDefaultScale(Size defaultScale)
    • isAutoScaleOn

      public boolean isAutoScaleOn()
    • setAutoScaleOn

      public void setAutoScaleOn(boolean autoScaleOn)
    • getDefaultScale

      public Size getDefaultScale()
    • getPlotColor

      public GraphColor getPlotColor()
    • setFont

      public void setFont(GraphFont font)
    • getFont

      public GraphFont getFont()
    • getGridExpressionParser

      public GridExpressionParser getGridExpressionParser()
    • setGridExpressionParser

      public void setGridExpressionParser(GridExpressionParser gridExpressionParser)
    • getLowerVisibleX

      public double getLowerVisibleX()
    • getUpperVisibleX

      public double getUpperVisibleX()
    • getLowerVisibleY

      public double getLowerVisibleY()
    • getUpperVisibleY

      public double getUpperVisibleY()
    • getGridColor

      public GraphColor getGridColor()
    • setGridColor

      public void setGridColor(GraphColor gridColor)
    • setGridSize

      public void setGridSize(Dimension gridSize)
    • setGridSize

      public void setGridSize(int wid, int hei)
    • getGridSize

      public Dimension getGridSize()
    • getMAX_ITERATIONS

      public static double getMAX_ITERATIONS()
    • getLocationOfOrigin

      public Point getLocationOfOrigin()
    • setLocationOfOrigin

      public void setLocationOfOrigin(Point locationOfOrigin)
    • getMajorAxesColor

      public GraphColor getMajorAxesColor()
    • setMajorAxesColor

      public void setMajorAxesColor(GraphColor majorAxesColor)
    • getMajorTickLength

      public int getMajorTickLength()
    • setMajorTickLength

      public final void setMajorTickLength(int majorTickLength)
    • getMinorTickLength

      public int getMinorTickLength()
    • setMinorTickLength

      public final void setMinorTickLength(int minorTickLength)
    • getLowerXLimit

      public double getLowerXLimit()
    • setRefreshingIndices

      public final void setRefreshingIndices(boolean refreshingIndices)
    • isRefreshingIndices

      public boolean isRefreshingIndices()
    • replotOnLimitChange

      public void replotOnLimitChange()
    • isShowGridLines

      public boolean isShowGridLines()
    • setShowGridLines

      public void setShowGridLines(boolean showGridLines)
    • setLowerXLimit

      public void setLowerXLimit(double lowerXLimit)
      Parameters:
      lowerXLimit - The lowest value up to which x should be plotted This value is re-computed in the method to ensure that it is always a unit number of xSteps away from the x coordinate(cartesian coordinate, not screen coordinates) of the left side of the graph
    • getUpperXLimit

      public double getUpperXLimit()
    • setUseTurbo

      public void setUseTurbo(boolean useTurbo)
    • isUseTurbo

      public boolean isUseTurbo()
    • setUpperXLimit

      public void setUpperXLimit(double upperXLimit)
      Parameters:
      upperXLimit - The highest value up to which x should be plotted This value is re-computed in the method to ensure that it is always a unit number of xSteps away from the x coordinate(cartesian coordinate, not screen coordinates) of the left side of the graph
    • getxStep

      public double getxStep()
    • setxStep

      public void setxStep(double xStep)
    • setyStep

      public void setyStep(double yStep)
    • getyStep

      public double getyStep()
    • setLabelAxis

      public void setLabelAxis(boolean labelAxis)
    • isLabelAxis

      public boolean isLabelAxis()
    • setTickColor

      public void setTickColor(GraphColor tickColor)
    • getTickColor

      public GraphColor getTickColor()
    • addFunction

      public void addFunction(String function)
      Parameters:
      function - A command string consisting of functions (geometric and algebraic) to be added to the graph. The functions are separated by a semicolon(;) Calling this method will ensure that the functions contained in the command will be added to the ones already plotted on the graph. An example of the format of function is: [-200,200,300,-200:][1,3,-2,1:];y=@(x)3x+1;y1=@(x)sin(3*x-1)
    • setFunction

      public void setFunction(String function)
      Parameters:
      function - A command string consisting of functions (geometric and algebraic) to be added to the graph. The functions are separated by a semicolon(;) Calling this method will ensure that the functions contained in the command alone will be the functions to be plotted on the graph.
    • drawMajorAxes

      public void drawMajorAxes(DrawingContext g)
      Draws the 2 major axes, the x and the y and labels them.
      Parameters:
      g - The Graphics object used to draw.
    • draw

      public void draw(DrawingContext g)
      draws the grid
      Parameters:
      g - the Graphics object used to draw.
    • convertGridSizeToUserDistanceAlongX

      public double convertGridSizeToUserDistanceAlongX(int gridDistance)
      Parameters:
      gridDistance - The horizontal distance along the grid.
      Returns:
      the equivalent horizontal distance in user terms.
    • convertGridSizeToUserDistanceAlongY

      public double convertGridSizeToUserDistanceAlongY(int gridDistance)
      Parameters:
      gridDistance - The vertical distance along the grid.
      Returns:
      the vertical distance in user terms.
    • convertUserDistanceAlongX_ToGridSize

      public long convertUserDistanceAlongX_ToGridSize(double userX)
      Parameters:
      userX - The horizontal distance along the grid in user terms.
      Returns:
      the equivalent horizontal distance in screen terms.
    • convertUserDistanceAlongY_ToGridSize

      public long convertUserDistanceAlongY_ToGridSize(double userY)
      Parameters:
      userY - The vertical distance along the grid in user terms.
      Returns:
      the equivalent vertical distance in screen terms .
    • convertScreenPointToGraphPointzaa

      public Point convertScreenPointToGraphPointzaa(Point screenPoint)
      Converts a point on the screen to its equivalent point in mathematics relative to the specified origin. It is useful basically in labeling the axes during its construction.
      Parameters:
      screenPoint - The point on the screen.
      Returns:
      the point on the graph.
    • convertScreenPointToGraphCoords

      public double[] convertScreenPointToGraphCoords(int screenX, int screenY)
      This method does basically what convertScreenPointToGraphCoords(int, int) does. But it returns its result as an array of size 2. Converts the x and y coordinates of a point on the screen to its equivalent point in mathematics relative to the specified origin. It is useful basically in labeling the axes during its construction.
      Parameters:
      screenX - The x coordinate of the point on the screen.
      screenY - The y coordinate of the point on the screen.
      Returns:
      an array of size 2 having the graph equivalent of the screen's x coordinate in index 0 and the graph equivalent of the screen's y coordinate in index 1
    • convertGraphPointToScreenPoint

      public Point convertGraphPointToScreenPoint(Point userPoint)
      Say the user is about to identify plot Point p = [2,4] on the screen, He passes it in to the draw method as convertGraphPointToScreenPoint(p). and gets his plot.This method takes care of all conversions from the math coordinates to the screen coordinates.
      Parameters:
      userPoint - The point on the graph to be drawn on the screen.
      Returns:
      the screen equivalent of the point.
    • convertGraphPointToScreenCoords

      public int[] convertGraphPointToScreenCoords(double graphX, double graphY)
      This does the same thing as convertGraphPointToScreenPoint(math.Point) but it returns the result in an array of size two instead.
      Parameters:
      graphX - The y coordinate of the point to be drawn on the screen.
      graphY - The y coordinate of the point to be drawn on the screen.
      Returns:
      an array containing the screen equivalent of coordinate x in index 0 and the the screen equivalent of coordinate y in index 1.
    • computeXMinBoundPossibleOnScreen

      public final void computeXMinBoundPossibleOnScreen()
      *
    • computeXMaxBoundPossibleOnScreen

      public final void computeXMaxBoundPossibleOnScreen()
    • computeYMinBoundPossibleOnScreen

      public final void computeYMinBoundPossibleOnScreen()
    • computeYMaxBoundPossibleOnScreen

      public final void computeYMaxBoundPossibleOnScreen()
    • generateAutomaticScale

      public void generateAutomaticScale()
      Generates automatically the numeric drawing parameters for the function.