org.opensourcephysics.display
Class FunctionDrawer

java.lang.Object
  extended by org.opensourcephysics.display.FunctionDrawer
All Implemented Interfaces:
Drawable, Measurable, Function

public class FunctionDrawer
extends java.lang.Object
implements Drawable, Measurable, Function

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
 java.awt.Color color
           
 boolean functionChanged
           
 
Constructor Summary
FunctionDrawer(Function f)
          Contstucts 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
 void draw(DrawingPanel panel, java.awt.Graphics g)
          Draw the function on a drawing panel.
 double evaluate(double x)
          Evalutes the function.
 java.awt.geom.GeneralPath 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[] getXRange()
          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[] getYRange()
          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 isMeasured()
          Determines if information is available to set min/max values.
 void setColor(java.awt.Color c)
          Sets the drawing color.
 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
 

Field Detail

color

public java.awt.Color color

functionChanged

public boolean functionChanged
Constructor Detail

FunctionDrawer

public FunctionDrawer(Function f)
Contstucts a FunctionDrawer with optimum resolution.

Parameters:
f - the function that will be drawn.

FunctionDrawer

public FunctionDrawer(Function f,
                      double xmin,
                      double xmax,
                      int numpts,
                      boolean filled)
Creates the function drawer and initialzies the domain with the given values.

Parameters:
f - Function
xmin - double
xmax - double
numpts - int
filled - boolean fills the area under the curve with the drawing color when true
Method Detail

evaluate

public double evaluate(double x)
Evalutes the function.

Specified by:
evaluate in interface Function
Parameters:
x -
Returns:
value of 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 range
numpts - the number of points to display
filled - fills the area under the curve with the drawing color when true

getPath

public java.awt.geom.GeneralPath 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

draw

public void draw(DrawingPanel panel,
                 java.awt.Graphics g)
Draw the function on a drawing panel.

Specified by:
draw in interface Drawable
Parameters:
panel - the drawing panel
g - the graphics context

setFilled

public void setFilled(boolean _filled)
Fills the area under the curve when true.

Parameters:
_filled - boolean

setColor

public void setColor(java.awt.Color c)
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 interface Measurable
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 interface Measurable
Returns:
minimum

getXMax

public double getXMax()
Description copied from interface: Measurable
Gets the maximum x needed to draw this object.

Specified by:
getXMax in interface Measurable
Returns:
maximum

getYMin

public double getYMin()
Description copied from interface: Measurable
Gets the minimum y needed to draw this object.

Specified by:
getYMin in interface Measurable
Returns:
minimum

getYMax

public double getYMax()
Description copied from interface: Measurable
Gets the maximum y needed to draw this object.

Specified by:
getYMax in interface Measurable
Returns:
minimum