| java.lang.Object edu.hws.jcm.draw.Drawable edu.hws.jcm.draw.VectorField
VectorField | public class VectorField extends Drawable implements Computable(Code) | | 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."
|
Field Summary | |
final public static int | ARROWS One of the possible styles for displaying a VectorField: as a direction field shown as
arrows of equal length. | final public 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. | final public static int | LINES One of the possible styles for displaying a VectorField: as a direction field shown as
tangent lines. | final public 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. | final public 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. |
Constructor Summary | |
public | VectorField() Create a VectorField object with nothing to graph. | 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. | 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. |
Method Summary | |
public synchronized 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. | public synchronized void | draw(Graphics g, boolean coordsChanged) Draw the vector field (possibly recomputing the data if the CoordinateRect has changed). | public Color | getColor() Get the color that is used to draw the vector field. | public int | getPixelSpacing() Get the value of the pixelSpacing property, which determines the grid spacing for the vector field. | public int | getStyle() Get the style in which the vector field is displayed. | public Function | getXFunction() Get the (possibly null) function that gives the x-component of the vector field. | public Function | getYFunction() Get the (possibly null) function that gives the y-component of the vector field. | public void | setColor(Color c) Set the color to be used for drawing the vector field. | public synchronized void | setFunctions(Function dx, Function dy) Sets the functions that give the components of the vector field. | 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. | public void | setStyle(int style) Set the style in which the vector field is displayed. | public synchronized void | setXFunction(Function dx) Set the function that gives the x-component of the vector field. | public synchronized void | setYFunction(Function dy) Set the function that gives the y-component of the vector field. |
ARROWS | final public static int ARROWS(Code) | | 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.
|
CLAMPED_VECTORS | final public static int CLAMPED_VECTORS(Code) | | 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.
|
LINES | final public static int LINES(Code) | | 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.
|
SCALED_LINES | final public static int SCALED_LINES(Code) | | 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.
|
SCALED_VECTORS | final public static int SCALED_VECTORS(Code) | | 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.
|
VectorField | public VectorField()(Code) | | 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)(Code) | | 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.
|
VectorField | public VectorField(Function xFunc, Function yFunc, int style)(Code) | | 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 thisis null, then nothing will be drawn. Parameters: yFunc - A Function of two variables giving the y-component of the vector field. If thisis null, then nothing will be drawn. Parameters: style - The style in which the direction field is drawn. This can be one of theconstants 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 haslength equal to the grid spacing), or SCALED_LINES (lines scaled so longest has lengthequal to the grid spacing). |
compute | public synchronized void compute()(Code) | | 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.
|
draw | public synchronized void draw(Graphics g, boolean coordsChanged)(Code) | | Draw the vector field (possibly recomputing the data if the CoordinateRect has changed).
|
getColor | public Color getColor()(Code) | | Get the color that is used to draw the vector field.
|
getPixelSpacing | public int getPixelSpacing()(Code) | | Get the value of the pixelSpacing property, which determines the grid spacing for the vector field.
|
getStyle | public int getStyle()(Code) | | Get the style in which the vector field is displayed.
|
getXFunction | public Function getXFunction()(Code) | | Get the (possibly null) function that gives the x-component of the vector field.
|
getYFunction | public Function getYFunction()(Code) | | Get the (possibly null) function that gives the y-component of the vector field.
|
setColor | public void setColor(Color c)(Code) | | Set the color to be used for drawing the vector field. The default color is light gray.
|
setFunctions | public synchronized void setFunctions(Function dx, Function dy)(Code) | | 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.
|
setPixelSpacing | public void setPixelSpacing(int spacing)(Code) | | 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.
|
setStyle | public void setStyle(int style)(Code) | | 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.
|
setXFunction | public synchronized void setXFunction(Function dx)(Code) | | 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.
|
setYFunction | public synchronized void setYFunction(Function dy)(Code) | | 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.
|
|
|