Class Grid
java.lang.Object
com.github.gbenroscience.math.graph.Grid
- Author:
- JIBOYE Oluwagbemiro Olaoluwa
-
Nested Class Summary
Nested Classes -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionGrid(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) 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 Summary
Modifier and TypeMethodDescriptionvoidaddFunction(String function) final voidfinal void*final voidfinal voidint[]convertGraphPointToScreenCoords(double graphX, double graphY) This does the same thing asconvertGraphPointToScreenPoint(math.Point)but it returns the result in an array of size two instead.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).doubleconvertGridSizeToUserDistanceAlongX(int gridDistance) doubleconvertGridSizeToUserDistanceAlongY(int gridDistance) double[]convertScreenPointToGraphCoords(int screenX, int screenY) This method does basically whatconvertScreenPointToGraphCoords(int, int)does.convertScreenPointToGraphPointzaa(Point screenPoint) Converts a point on the screen to its equivalent point in mathematics relative to the specified origin.longconvertUserDistanceAlongX_ToGridSize(double userX) longconvertUserDistanceAlongY_ToGridSize(double userY) voiddraws the gridvoidDraws the 2 major axes, the x and the y and labels them.voidGenerates automatically the numeric drawing parameters for the function.intgetDRG()getFont()doubledoubledoubleintstatic doubleintdoubledoubledoubledoublegetxStep()doublegetyStep()booleanbooleanbooleanbooleanbooleanvoidvoidsetAutoScaleOn(boolean autoScaleOn) voidsetComponent(AbstractView component) voidsetDefaultScale(Size defaultScale) voidsetDRG(int DRG) voidvoidsetFunction(String function) voidsetGridColor(GraphColor gridColor) voidsetGridExpressionParser(GridExpressionParser gridExpressionParser) voidsetGridSize(int wid, int hei) voidsetGridSize(Dimension gridSize) voidsetHorizontalAxisLabel(Variable horizontalAxisLabel) voidsetLabelAxis(boolean labelAxis) voidsetLocationOfOrigin(Point locationOfOrigin) voidsetLowerXLimit(double lowerXLimit) voidsetMajorAxesColor(GraphColor majorAxesColor) final voidsetMajorTickLength(int majorTickLength) final voidsetMinorTickLength(int minorTickLength) voidsetPlotColor(GraphColor plotColor) final voidsetRefreshingIndices(boolean refreshingIndices) voidsetShowGridLines(boolean showGridLines) voidsetTickColor(GraphColor tickColor) voidsetUpperXLimit(double upperXLimit) voidsetUseTurbo(boolean useTurbo) voidsetVerticalAxisLabel(Variable verticalAxisLabel) voidsetxStep(double xStep) voidsetyStep(double yStep) voidvalidates thexStepattribute.
-
Field Details
-
MIN_GRID_SIZE
public static final int MIN_GRID_SIZE- See Also:
-
MAX_GRID_SIZE
public static final int MAX_GRID_SIZE- See Also:
-
-
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 graphlowerXLimit- 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 thexStepattribute. It checks if the number of iterations is not greater. -
setComponent
-
getComponent
-
setDRG
public void setDRG(int DRG) -
getDRG
public int getDRG() -
getHorizontalAxisLabel
-
setHorizontalAxisLabel
-
getVerticalAxisLabel
-
setVerticalAxisLabel
-
setPlotColor
-
setDefaultScale
-
isAutoScaleOn
public boolean isAutoScaleOn() -
setAutoScaleOn
public void setAutoScaleOn(boolean autoScaleOn) -
getDefaultScale
-
getPlotColor
-
setFont
-
getFont
-
getGridExpressionParser
-
setGridExpressionParser
-
getLowerVisibleX
public double getLowerVisibleX() -
getUpperVisibleX
public double getUpperVisibleX() -
getLowerVisibleY
public double getLowerVisibleY() -
getUpperVisibleY
public double getUpperVisibleY() -
getGridColor
-
setGridColor
-
setGridSize
-
setGridSize
public void setGridSize(int wid, int hei) -
getGridSize
-
getMAX_ITERATIONS
public static double getMAX_ITERATIONS() -
getLocationOfOrigin
-
setLocationOfOrigin
-
getMajorAxesColor
-
setMajorAxesColor
-
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 ofxSteps 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 ofxSteps 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
-
getTickColor
-
addFunction
- 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
- 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
Draws the 2 major axes, the x and the y and labels them.- Parameters:
g- The Graphics object used to draw.
-
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
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 whatconvertScreenPointToGraphCoords(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
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 asconvertGraphPointToScreenPoint(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.
-