Package edu.hws.jcm.draw
Class VectorField
java.lang.Object
edu.hws.jcm.draw.Drawable
edu.hws.jcm.draw.VectorField
- All Implemented Interfaces:
Computable
,Serializable
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:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
One of the possible styles for displaying a VectorField: as a direction field shown as arrows of equal length.static final int
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 final int
One of the possible styles for displaying a VectorField: as a direction field shown as tangent lines.static final int
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 final int
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
ConstructorsConstructorDescriptionCreate 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
Modifier and TypeMethodDescriptionvoid
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 the vector field (possibly recomputing the data if the CoordinateRect has changed).getColor()
Get the color that is used to draw the vector field.int
Get the value of the pixelSpacing property, which determines the grid spacing for the vector field.int
getStyle()
Get the style in which the vector field is displayed.Get the (possibly null) function that gives the x-component of the vector field.Get the (possibly null) function that gives the y-component of the vector field.void
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
setPixelSpacing
(int spacing) Set the value of the pixelSpacing property, which determines the grid spacing for the vector field.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 edu.hws.jcm.draw.Drawable
getVisible, needsRedraw, setOwnerData, setVisible
-
Field Details
-
ARROWS
public static final int ARROWSOne 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:
-
LINES
public static final int LINESOne 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:
-
CLAMPED_VECTORS
public static final int CLAMPED_VECTORSOne 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:
-
SCALED_LINES
public static final int SCALED_LINESOne 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:
-
SCALED_VECTORS
public static final int SCALED_VECTORSOne 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:
-
-
Constructor Details
-
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
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
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 Details
-
setColor
Set the color to be used for drawing the vector field. The default color is light gray. -
getColor
Get the color that is used to draw the vector field. -
setFunctions
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. -
setXFunction
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
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. -
getXFunction
Get the (possibly null) function that gives the x-component of the vector field. -
getYFunction
Get the (possibly null) function that gives the y-component of the vector field. -
getStyle
public int getStyle()Get the style in which the vector field is displayed. -
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. -
getPixelSpacing
public int getPixelSpacing()Get the value of the pixelSpacing property, which determines the grid spacing for the vector field. -
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. -
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 interfaceComputable
-
draw
Draw the vector field (possibly recomputing the data if the CoordinateRect has changed).- Specified by:
draw
in classDrawable
- Parameters:
g
- The graphics context in which the Drawble is to be drawn. (The drawing can change the color in g, but should not permanently change font, painting mode, etc. Thus, every drawable is responsible for setting the color it wants to use.)coordsChanged
- Indicates whether the CoordinateRect has changed.
-