Class FunctionDrawer

java.lang.Object
org.opensourcephysics.display.FunctionDrawer
All Implemented Interfaces:
Drawable, Measurable, Function
Direct Known Subclasses:
UncertainFunctionDrawer

public class FunctionDrawer extends 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 Details

    • xrange

      protected double[] xrange
    • yrange

      protected double[] yrange
    • numpts

      protected int numpts
    • generalPath

      protected GeneralPath generalPath
    • function

      protected Function function
    • filled

      protected boolean filled
    • measured

      protected boolean measured
    • color

      public Color color
    • functionChanged

      public boolean functionChanged
    • enabled

      protected boolean enabled
  • Constructor Details

    • FunctionDrawer

      public FunctionDrawer(Function f)
      Constructs 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 Details

    • setEnabled

      public void setEnabled(boolean b)
    • evaluate

      public double evaluate(double x)
      Evaluates 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 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
    • checkRange

      protected void checkRange(DrawingPanel panel)
    • draw

      public void draw(DrawingPanel panel, 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(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