net.sourceforge.webcompmath.draw
Class VectorField

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

public class VectorField
extends Drawable
implements Computable

A VectorField displays lines or arrows on a grid of points where the direction and/or lengths are given by two functions (f1(x,y),f2(x,y)). This is probably more useful as a "direction field" than as a "vector field."

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 ARROWS
          One of the possible styles for displaying a VectorField: as a direction field shown as arrows of equal length.
static int CLAMPED_VECTORS
          One of the possible styles for displaying a VectorField: as a vector field where a vector is shown as an arrow from (x,y) to (x+xFunc(x,y),y+xFunc(x,y)), except that a maximum length is imposed.
static int LINES
          One of the possible styles for displaying a VectorField: as a direction field shown as tangent lines.
protected  int lineWidth
          The width, in pixels, of lines.
static int SCALED_LINES
          One of the possible styles for displaying a VectorField: as a field of tangent lines where the length of the line is proportional to the length of the vector.
static int SCALED_VECTORS
          One of the possible styles for displaying a VectorField: as a vector field where a vector is shown as an arrow with length proportional to the length of the vector.
 
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
VectorField()
          Create a VectorField object with nothing to graph.
VectorField(Function xFunc, Function yFunc)
          Create a VectorField that will be displayed using the default style, as a direction field of equal-length arrows.
VectorField(Function xFunc, Function yFunc, int style)
          Create a VectorField with the specified functions and style.
 
Method Summary
 void compute()
          Recompute data for the vector field and make sure that the area of the display canvas that shows the vector field is redrawn.
 void draw(java.awt.Graphics g, boolean coordsChanged)
          Draw the vector field (possibly recomputing the data if the CoordinateRect has changed).
 java.awt.Color getColor()
          Get the color that is used to draw the vector field.
 int getLineWidth()
          Get the width, in pixels, of lines that are drawn.
 int getPixelSpacing()
          Get the value of the pixelSpacing property, which determines the grid spacing for the vector field.
 double getRealXSpacing()
          Get the value of the realXSpacing property, which determines the grid spacing for the vector field in the x direction.
 double getRealYSpacing()
          Get the value of the realYSpacing property, which determines the grid spacing for the vector field in the x direction.
 int getStyle()
          Get the style in which the vector field is displayed.
 Function getXFunction()
          Get the (possibly null) function that gives the x-component of the vector field.
 Function getYFunction()
          Get the (possibly null) function that gives the y-component of the vector field.
 void setColor(java.awt.Color c)
          Set the color to be used for drawing the vector field.
 void setFunctions(Function dx, Function dy)
          Sets the functions that give the components of the vector field.
 void setLineWidth(int width)
          Set the width, in pixels, of lines that are drawn.
 void setPixelSpacing(int spacing)
          Set the value of the pixelSpacing property, which determines the grid spacing for the vector field.
 void setRealXSpacing(double realXSpacing)
          Set the value of the realXSpacing property, which determines the grid spacing for the vector field in the x direction.
 void setRealYSpacing(double realYSpacing)
          Set the value of the realYSpacing property, which determines the grid spacing for the vector field in the x direction.
 void setStyle(int style)
          Set the style in which the vector field is displayed.
 void setXFunction(Function dx)
          Set the function that gives the x-component of the vector field.
 void setYFunction(Function dy)
          Set the function that gives the y-component of the vector field.
 
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

ARROWS

public static final int ARROWS
One of the possible styles for displaying a VectorField: as a direction field shown as arrows of equal length. The point where the vector is computed is the tail of the arrow.

See Also:
Constant Field Values

LINES

public static final int LINES
One of the possible styles for displaying a VectorField: as a direction field shown as tangent lines. The point where the vector is computed is the center of the line.

See Also:
Constant Field Values

CLAMPED_VECTORS

public static final int CLAMPED_VECTORS
One of the possible styles for displaying a VectorField: as a vector field where a vector is shown as an arrow from (x,y) to (x+xFunc(x,y),y+xFunc(x,y)), except that a maximum length is imposed.

See Also:
Constant Field Values

SCALED_LINES

public static final int SCALED_LINES
One of the possible styles for displaying a VectorField: as a field of tangent lines where the length of the line is proportional to the length of the vector.

See Also:
Constant Field Values

SCALED_VECTORS

public static final int SCALED_VECTORS
One of the possible styles for displaying a VectorField: as a vector field where a vector is shown as an arrow with length proportional to the length of the vector. The lengths are scaled so that the longest arrow has length equal to the grid spacing.

See Also:
Constant Field Values

lineWidth

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

Constructor Detail

VectorField

public VectorField()
Create a VectorField object with nothing to graph. The functions and other values can be set later. The default display style is as a direction field of equal-length arrows.


VectorField

public VectorField(Function xFunc,
                   Function yFunc)
Create a VectorField that will be displayed using the default style, as a direction field of equal-length arrows. If either of the functions is null, nothing will be displayed. If non-null, the functions must be functions of two variables.

Parameters:
xFunc - A Function of two variables giving the x-component of the vector field. If this is null, then nothing will be drawn.
yFunc - A Function of two variables giving the y-component of the vector field. If this is null, then nothing will be drawn.

VectorField

public VectorField(Function xFunc,
                   Function yFunc,
                   int style)
Create a VectorField with the specified functions and style.

Parameters:
xFunc - A Function of two variables giving the x-component of the vector field. If this is null, then nothing will be drawn.
yFunc - A Function of two variables giving the y-component of the vector field. If this is null, then nothing will be drawn.
style - The style in which the direction field is drawn. This can be one of the constants ARROWS (a direction field of equal-lenth arrows), LINES (equal length lines), CLAMPED_VECTORS (vectors drawn at actual length, unless too long), SCALED_VECTORS (vectors scaled so longest has length equal to the grid spacing), or SCALED_LINES (lines scaled so longest has length equal to the grid spacing).
Method Detail

setColor

public void setColor(java.awt.Color c)
Set the color to be used for drawing the vector field. The default color is light gray.

Parameters:
c - field line color

getColor

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

Returns:
field line color

setFunctions

public void setFunctions(Function dx,
                         Function dy)
Sets the functions that give the components of the vector field. If either function is null, then nothing is drawn. If non-null, each function must be a function of two variables.

Parameters:
dx - function that gives the x-component of the vector field
dy - function that gives the y-component of the vector field

setXFunction

public void setXFunction(Function dx)
Set the function that gives the x-component of the vector field. If this is null, then nothing is drawn. If non-null, it must be a function of two variables.

Parameters:
dx - function that gives the x-component of the vector field

setYFunction

public void setYFunction(Function dy)
Set the function that gives the y-component of the vector field. If this is null, then nothing is drawn. If non-null, it must be a function of two variables.

Parameters:
dy - function that gives the y-component of the vector field

getXFunction

public Function getXFunction()
Get the (possibly null) function that gives the x-component of the vector field.

Returns:
function that gives the x-component of the vector field

getYFunction

public Function getYFunction()
Get the (possibly null) function that gives the y-component of the vector field.

Returns:
function that gives the y-component of the vector field

getStyle

public int getStyle()
Get the style in which the vector field is displayed.

Returns:
ARROWS, LINES, CLAMPED_VECTORS, SCALED_LINES, or SCALED_VECTORS

setStyle

public void setStyle(int style)
Set the style in which the vector field is displayed. This should be one of the constants ARROWS, LINES, CLAMPED_VECTORS, SCALED_LINES, or SCALED_VECTORS.

Parameters:
style - vector field style constant

getPixelSpacing

public int getPixelSpacing()
Get the value of the pixelSpacing property, which determines the grid spacing for the vector field.

Returns:
pixel spacing

setPixelSpacing

public void setPixelSpacing(int spacing)
Set the value of the pixelSpacing property, which determines the grid spacing for the vector field. The value will be clamped to the range from 5 to 200. The default value is 30.

Parameters:
spacing - pixel spacing

getRealXSpacing

public double getRealXSpacing()
Get the value of the realXSpacing property, which determines the grid spacing for the vector field in the x direction. If either realXSpacing or realYSpacing are zero, then pixelSpacing is used. If both are non-zero, then real spacing is used instead of pixelSpacing

Returns:
the real spacing

setRealXSpacing

public void setRealXSpacing(double realXSpacing)
Set the value of the realXSpacing property, which determines the grid spacing for the vector field in the x direction. If either realXSpacing or realYSpacing are zero, then pixelSpacing is used. If both are non-zero, then real spacing is used instead of pixelSpacing

Parameters:
realXSpacing - the real spacing

getRealYSpacing

public double getRealYSpacing()
Get the value of the realYSpacing property, which determines the grid spacing for the vector field in the x direction. If either realXSpacing or realYSpacing are zero, then pixelSpacing is used. If both are non-zero, then real spacing is used instead of pixelSpacing

Returns:
the real spacing

setRealYSpacing

public void setRealYSpacing(double realYSpacing)
Set the value of the realYSpacing property, which determines the grid spacing for the vector field in the x direction. If either realXSpacing or realYSpacing are zero, then pixelSpacing is used. If both are non-zero, then real spacing is used instead of pixelSpacing

Parameters:
realYSpacing - the real spacing

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

compute

public void compute()
Recompute data for the vector field and make sure that the area of the display canvas that shows the vector field 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 vector field (possibly recomputing the data if the CoordinateRect has changed).

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