Package org.opensourcephysics.display
Class FunctionDrawer
java.lang.Object
org.opensourcephysics.display.FunctionDrawer
- All Implemented Interfaces:
Drawable,Measurable,Function
- Direct Known Subclasses:
UncertainFunctionDrawer
FunctionDrawer draws a function from xmin to xmax.
The function will be evaluated at every screen pixel unless the domain is set
using the initialize method.
- Version:
- 1.0
- Author:
- Wolfgang Christian, Joshua Gould
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected booleanprotected booleanprotected Functionbooleanprotected GeneralPathprotected booleanprotected intprotected double[]protected double[] -
Constructor Summary
ConstructorsConstructorDescriptionConstructs a FunctionDrawer with optimum resolution.FunctionDrawer(Function f, double xmin, double xmax, int numpts, boolean filled) Creates the function drawer and initialzies the domain with the given values. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidcheckRange(DrawingPanel panel) voiddraw(DrawingPanel panel, Graphics g) Draw the function on a drawing panel.doubleevaluate(double x) Evaluates the function.getPath()Gets the general path that draws this function.doublegetXMax()Gets the maximum x needed to draw this object.doublegetXMin()Gets the minimum x needed to draw this object.double[]Get the range of x values over which the function has been evaluated.doublegetYMax()Gets the maximum y needed to draw this object.doublegetYMin()Gets the minimum y needed to draw this object.double[]Get the minimum and maximum y values for the function.voidinitialize(double xmin, double xmax, int numpts, boolean filled) Initialize the function range and the number of display points.booleanDetermines if information is available to set min/max values.voidSets the drawing color.voidsetEnabled(boolean b) voidsetFilled(boolean _filled) Fills the area under the curve when true.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.opensourcephysics.display.Drawable
isInteractive
-
Field Details
-
xrange
protected double[] xrange -
yrange
protected double[] yrange -
numpts
protected int numpts -
generalPath
-
function
-
filled
protected boolean filled -
measured
protected boolean measured -
color
-
functionChanged
public boolean functionChanged -
enabled
protected boolean enabled
-
-
Constructor Details
-
FunctionDrawer
Constructs a FunctionDrawer with optimum resolution.- Parameters:
f- the function that will be drawn.
-
FunctionDrawer
Creates the function drawer and initialzies the domain with the given values.- Parameters:
f- Functionxmin- doublexmax- doublenumpts- intfilled- boolean fills the area under the curve with the drawing color when true
-
-
Method Details
-
setEnabled
public void setEnabled(boolean b) -
evaluate
public double evaluate(double x) Evaluates the function. -
initialize
public void initialize(double xmin, double xmax, int numpts, boolean filled) Initialize the function range and the number of display points.- Parameters:
xmin- the beginning value of the range.xmax- the ending value for the rangenumpts- the number of points to displayfilled- fills the area under the curve with the drawing color when true
-
getPath
Gets the general path that draws this function.- Returns:
- GeneralPath
-
getXRange
public double[] getXRange()Get the range of x values over which the function has been evaluated.- Returns:
- double[2] the xmin and xmax values
-
getYRange
public double[] getYRange()Get the minimum and maximum y values for the function.- Returns:
- double[2] the ymin and ymax values
-
checkRange
-
draw
Draw the function on a drawing panel. -
setFilled
public void setFilled(boolean _filled) Fills the area under the curve when true.- Parameters:
_filled- boolean
-
setColor
Sets the drawing color.- Parameters:
c- Color
-
isMeasured
public boolean isMeasured()Description copied from interface:MeasurableDetermines if information is available to set min/max values. Objects that store data should return false if data is null.- Specified by:
isMeasuredin interfaceMeasurable- Returns:
- true if min/max values are valid
-
getXMin
public double getXMin()Description copied from interface:MeasurableGets the minimum x needed to draw this object.- Specified by:
getXMinin interfaceMeasurable- Returns:
- minimum
-
getXMax
public double getXMax()Description copied from interface:MeasurableGets the maximum x needed to draw this object.- Specified by:
getXMaxin interfaceMeasurable- Returns:
- maximum
-
getYMin
public double getYMin()Description copied from interface:MeasurableGets the minimum y needed to draw this object.- Specified by:
getYMinin interfaceMeasurable- Returns:
- minimum
-
getYMax
public double getYMax()Description copied from interface:MeasurableGets the maximum y needed to draw this object.- Specified by:
getYMaxin interfaceMeasurable- Returns:
- minimum
-