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 boolean
protected boolean
protected Function
boolean
protected GeneralPath
protected boolean
protected int
protected 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 void
checkRange
(DrawingPanel panel) void
draw
(DrawingPanel panel, Graphics g) Draw the function on a drawing panel.double
evaluate
(double x) Evaluates the function.getPath()
Gets the general path that draws this function.double
getXMax()
Gets the maximum x needed to draw this object.double
getXMin()
Gets the minimum x needed to draw this object.double[]
Get the range of x values over which the function has been evaluated.double
getYMax()
Gets the maximum y needed to draw this object.double
getYMin()
Gets the minimum y needed to draw this object.double[]
Get the minimum and maximum y values for the function.void
initialize
(double xmin, double xmax, int numpts, boolean filled) Initialize the function range and the number of display points.boolean
Determines if information is available to set min/max values.void
Sets the drawing color.void
setEnabled
(boolean b) void
setFilled
(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, wait
Methods 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:Measurable
Determines if information is available to set min/max values. Objects that store data should return false if data is null.- Specified by:
isMeasured
in interfaceMeasurable
- Returns:
- true if min/max values are valid
-
getXMin
public double getXMin()Description copied from interface:Measurable
Gets the minimum x needed to draw this object.- Specified by:
getXMin
in interfaceMeasurable
- Returns:
- minimum
-
getXMax
public double getXMax()Description copied from interface:Measurable
Gets the maximum x needed to draw this object.- Specified by:
getXMax
in interfaceMeasurable
- Returns:
- maximum
-
getYMin
public double getYMin()Description copied from interface:Measurable
Gets the minimum y needed to draw this object.- Specified by:
getYMin
in interfaceMeasurable
- Returns:
- minimum
-
getYMax
public double getYMax()Description copied from interface:Measurable
Gets the maximum y needed to draw this object.- Specified by:
getYMax
in interfaceMeasurable
- Returns:
- minimum
-