net.sourceforge.webcompmath.draw
Class ParametricCurve

java.lang.Object
  extended by java.awt.Component
      extended by net.sourceforge.webcompmath.draw.Drawable
          extended by net.sourceforge.webcompmath.draw.ParametricCurve
All Implemented Interfaces:
java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, Computable
Direct Known Subclasses:
WCMParametricCurveBean

public class ParametricCurve
extends Drawable
implements Computable

A ParametricCurve is defined by two functions, x(t) and y(t) of a variable, t, for t in a specified interval. The curve is simply defined as a sequence of line segments connecting points of the form (x(t),y(t)), except where one of the functions is undefined. Also, in some cases a discontinuity will be detected and no line will be drawn between two of the points.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
static int DASHED_STYLE
          Specifies that the shape should be drawn with dashed line(s).
protected  int lineStyle
          The line style, SOLID_STYLE or DASHED_STYLE
protected  int lineWidth
          The width, in pixels, of lines.
static int SOLID_STYLE
          Specifies that the shape should be drawn with solid line(s).
 
Fields inherited from class net.sourceforge.webcompmath.draw.Drawable
canvas, coords
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
ParametricCurve()
          Create a ParametricCurve with nothing to graph.
ParametricCurve(Function xFunc, Function yFunc)
          Create a parametric curve with x and y coordinates given by the specified functions of the parameter t.
ParametricCurve(Function xFunc, Function yFunc, Value tmin, Value tmax, Value intervals)
          Create a parametric curve with the specified values.
 
Method Summary
 void compute()
          Recompute data for the graph and make sure that the area of the display canvas that shows the graph is redrawn.
 void draw(java.awt.Graphics g, boolean coordsChanged)
          Draw the graph (possibly recomputing the data if the CoordinateRect has changed).
 java.awt.Color getColor()
          Get the color that is used to draw the graph.
 Value getIntervals()
          Get the value object, possibly null, that determines the number of points on the curve.
 int getLineStyle()
          Get the line style, SOLID_STYLE or DASHED_STYLE
 int getLineWidth()
          Get the width, in pixels, of lines that are drawn.
 Value getTMax()
          Get the Value object, possibly null, that gives the right endpoint of the domain of the parameter.
 Value getTMin()
          Get the Value object, possibly null, that gives the left endpoint of the domain of the parameter.
 Function getXFunction()
          Get the (possibly null) function that gives the x-coordinate of the curve.
 Function getYFunction()
          Get the (possibly null) function that gives the y-coordinate of the curve.
 void setColor(java.awt.Color c)
          Set the color to be used for drawing the graph.
 void setFunctions(Function x, Function y)
          Sets the functions that gives the coordinates of the curve to be graphed.
 void setIntervals(Value intervalCount)
          Specify the number of subintervals into which the domain of the parametric curve is divided.
 void setLimits(Value tmin, Value tmax)
          Set the Value objects that specify the domain of the parameter.
 void setLineStyle(int lineStyle)
          Set the line style, SOLID_STYLE or DASHED_STYLE
 void setLineWidth(int width)
          Set the width, in pixels, of lines that are drawn.
 void setTMax(Value tmax)
          Set the Value object that gives the right endpoint of the domain of the parameter.
 void setTMin(Value tmin)
          Set the Value object that gives the left endpoint of the domain of the parameter.
 void setXFunction(Function x)
          Set the function that gives the x-coordinate of the curve to be graphed.
 void setYFunction(Function y)
          Set the function that gives the y-coordinate of the curve to be graphed.
 
Methods inherited from class net.sourceforge.webcompmath.draw.Drawable
getVisible, needsRedraw, setOwnerData, setVisible
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, deliverEvent, disable, disableEvents, dispatchEvent, doLayout, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAccessibleContext, getAlignmentX, getAlignmentY, getBackground, getBaseline, getBaselineResizeBehavior, getBounds, getBounds, getColorModel, getComponentAt, getComponentAt, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeys, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getListeners, getLocale, getLocation, getLocation, getLocationOnScreen, getMaximumSize, getMinimumSize, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, invalidate, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusCycleRoot, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, layout, list, list, list, list, list, locate, location, lostFocus, minimumSize, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paint, paintAll, paramString, postEvent, preferredSize, prepareImage, prepareImage, print, printAll, processComponentEvent, processEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, resize, resize, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeys, setFocusTraversalKeysEnabled, setFont, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle, update, validate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

lineWidth

protected int lineWidth
The width, in pixels, of lines. It is restricted to being an integer in the range from 1 to 10.


SOLID_STYLE

public static final int SOLID_STYLE
Specifies that the shape should be drawn with solid line(s). This is the default.

See Also:
Constant Field Values

DASHED_STYLE

public static final int DASHED_STYLE
Specifies that the shape should be drawn with dashed line(s).

See Also:
Constant Field Values

lineStyle

protected int lineStyle
The line style, SOLID_STYLE or DASHED_STYLE

Constructor Detail

ParametricCurve

public ParametricCurve()
Create a ParametricCurve with nothing to graph. The functions and other values can be set later.


ParametricCurve

public ParametricCurve(Function xFunc,
                       Function yFunc)
Create a parametric curve with x and y coordinates given by the specified functions of the parameter t. Defaults values are used for tmin, tmax, and the number of intervals. If either function is null, nothing is drawn.

Parameters:
xFunc - A Function of one variable giving the x-coordinate of points on the curve. If this is null, then nothing will be drawn.
yFunc - A Function of one variable giving the y-coordinate of points on the curve. If this is null, then nothing will be drawn.

ParametricCurve

public ParametricCurve(Function xFunc,
                       Function yFunc,
                       Value tmin,
                       Value tmax,
                       Value intervals)
Create a parametric curve with the specified values.

Parameters:
xFunc - A Function of one variable giving the x-coordinate of points on the curve. If this is null, then nothing will be drawn.
yFunc - A Function of one variable giving the y-coordinate of points on the curve. If this is null, then nothing will be drawn.
tmin - A Value object giving one endpoint of the domain of the parameter. If this is null, the default value -5 is used.
tmax - A Value object giving the second endpoint of the domain of the parameter. If this is null, the default value 5 is used. Note that it is not required that tmax be greater than tmin.
intervals - A Value object giving the number of intervals into which the domain is subdivided. If this is null, the default value 200 is used. The number of points on the curve will be the number of intervals plus one (unless a function is undefined at some value of the parameter or if a discontinuity is detected). The number of intervals is clamped to the range 1 to 10000. Values outside this range would certainly be unreasonable.
Method Detail

setColor

public void setColor(java.awt.Color c)
Set the color to be used for drawing the graph.

Parameters:
c - graph color

getColor

public java.awt.Color getColor()
Get the color that is used to draw the graph.

Returns:
graph color

setFunctions

public void setFunctions(Function x,
                         Function y)
Sets the functions that gives the coordinates of the curve to be graphed. If either function is null, then nothing is drawn. If non-null, each function must be a function of one variable.

Parameters:
x - function defining the x coord
y - function defining the y coord

setXFunction

public void setXFunction(Function x)
Set the function that gives the x-coordinate of the curve to be graphed. If this is null, then nothing is drawn. If non-null, it must be a function of one variable.

Parameters:
x - function defining the x coord

setYFunction

public void setYFunction(Function y)
Set the function that gives the y-coordinate of the curve to be graphed. If this is null, then nothing is drawn. If non-null, it must be a function of one variable.

Parameters:
y - function defining the yfunction defining the x coord coord

getXFunction

public Function getXFunction()
Get the (possibly null) function that gives the x-coordinate of the curve.

Returns:
function defining the x coord

getYFunction

public Function getYFunction()
Get the (possibly null) function that gives the y-coordinate of the curve.

Returns:
function defining the y coord

setIntervals

public void setIntervals(Value intervalCount)
Specify the number of subintervals into which the domain of the parametric curve is divided. The interval (tmin,tmax) is divided into subintervals. X and y coordinates of the parametric curve are computed at each endpoint of these subintervals, and then the points are connected by lines. If the parameter of this function is null, or if no interval count is ever specified, then a default value of 200 is used.

Parameters:
intervalCount - number of subintervals

getIntervals

public Value getIntervals()
Get the value object, possibly null, that determines the number of points on the curve.

Returns:
number of subintervals

setLimits

public void setLimits(Value tmin,
                      Value tmax)
Set the Value objects that specify the domain of the parameter.

Parameters:
tmin - min value of parameter
tmax - max value of parameter

getTMin

public Value getTMin()
Get the Value object, possibly null, that gives the left endpoint of the domain of the parameter.

Returns:
min value of parameter

getTMax

public Value getTMax()
Get the Value object, possibly null, that gives the right endpoint of the domain of the parameter.

Returns:
max value of parameter

setTMin

public void setTMin(Value tmin)
Set the Value object that gives the left endpoint of the domain of the parameter. If this is null, then a default value of -5 is used for the left endpoint. (Note: actually, it's not required that tmin be less than tmax, so this might really be the "right" endpoint.)

Parameters:
tmin - min value of parameter

setTMax

public void setTMax(Value tmax)
Set the Value object that gives the right endpoint of the domain of the parameter. If this is null, then a default value of 5 is used for the right endpoint. (Note: actually, it's not required that tmin be less than tmax, so this might really be the "left" endpoint.)

Parameters:
tmax - max value of parameter

setLineWidth

public void setLineWidth(int width)
Set the width, in pixels, of lines that are drawn. If set to 0, the thinnest possible line is drawn.

Parameters:
width - line width

getLineWidth

public int getLineWidth()
Get the width, in pixels, of lines that are drawn.

Returns:
line width

getLineStyle

public int getLineStyle()
Get the line style, SOLID_STYLE or DASHED_STYLE

Returns:
Returns the lineStyle.

setLineStyle

public void setLineStyle(int lineStyle)
Set the line style, SOLID_STYLE or DASHED_STYLE

Parameters:
lineStyle - The lineStyle to set.

compute

public void compute()
Recompute data for the graph and make sure that the area of the display canvas that shows the graph is redrawn. This method is ordinarily called by a Controller.

Specified by:
compute in interface Computable

draw

public void draw(java.awt.Graphics g,
                 boolean coordsChanged)
Draw the graph (possibly recomputing the data if the CoordinateRect has changed). This is not usually called directly.

Specified by:
draw in class Drawable
Parameters:
g - graphics context
coordsChanged - true or false