Package org.opensourcephysics.display2d
Class VectorPlot
java.lang.Object
org.opensourcephysics.display2d.VectorPlot
- All Implemented Interfaces:
Drawable
,Measurable
,Plot2D
VectorPlot renders a vector field in a drawing panel using arrows centered on
each grid point in the GridPointData.
The default representation of the vector field uses fixed length arrows to
show direction and color to show magnitude.
- Version:
- 1.0
- Author:
- Wolfgang Christian
-
Field Summary
FieldsFields inherited from interface org.opensourcephysics.display2d.Plot2D
CONTOUR_PLOT, GRID_PLOT, INTERPOLATED_PLOT, SURFACE_PLOT
-
Constructor Summary
ConstructorsConstructorDescriptionConstructs a VectorPlot without data.VectorPlot
(GridData _griddata) Constructs a VectorPlot that renders the given grid data. -
Method Summary
Modifier and TypeMethodDescriptionvoid
draw
(DrawingPanel panel, Graphics g) Draws this vector field in the given drawing panel.double
Gets the ceiling for scaling the z data.double
getFloor()
Gets the floor for scaling the z data.Gets the GridData object.static XML.ObjectLoader
Gets an XML.ObjectLoader to save and load data for this program.double
getXMax()
Gets the maximum x needed to draw this object.double
getXMin()
Gets the minimum x needed to draw this object.double
getYMax()
Gets the maximum y needed to draw this object.double
getYMin()
Gets the minimum y needed to draw this object.double
indexToX
(int i) Gets the x coordinate for the given index.double
indexToY
(int i) Gets the y coordinate for the given index.boolean
Gets the autoscale flag for z.boolean
Determines if information is available to set min/max values.boolean
Gets the symmetric z flag.void
scaleArrowLenghToGrid
(boolean scaleToGrid) Sets the autoscale flag for the arrow length.void
Sets the data to new values.void
Sets the values and the scale.void
setArrowType
(int type) Sets this vector field to draw vectors with filled shafts and arrowheads.void
setAutoscaleZ
(boolean isAutoscale, double floor, double ceil) Sets the autoscale flag and the floor and ceiling values.void
setColorPalette
(Color[] colors) Sets the colors that will be used between the floor and ceiling values.void
setExpandedZ
(boolean expanded, double expansionFactor) Expands the z scale so as to enhance values close to zero.void
setFloorCeilColor
(Color floorColor, Color ceilColor) Sets the floor and ceiling colors.void
setGridData
(GridData _griddata) Sets the data storage to the given value.void
Sets the color for grid line boundariesvoid
setIndexes
(int[] indexes) Sets the indexes for the data components that will be plotted.void
setPaletteType
(int mode) Sets the type of palette.void
setShowGridLines
(boolean showGrid) Outlines the data grid's boundaries.void
setSymmetricZ
(boolean symmetric) Forces the z-scale to be symmetric about zero.void
setVisible
(boolean vis) Sets this vector field to be visible.Shows how values map to colors.void
update()
Updates the vector field using the data array.int
xToIndex
(double x) Gets closest index from the given x world coordinate.int
yToIndex
(double y) Gets closest index from the given y world coordinate.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.opensourcephysics.display.Drawable
isInteractive
-
Field Details
-
STROKEDARROW
public static final int STROKEDARROW- See Also:
-
FILLEDARROW
public static final int FILLEDARROW- See Also:
-
-
Constructor Details
-
VectorPlot
public VectorPlot()Constructs a VectorPlot without data. -
VectorPlot
Constructs a VectorPlot that renders the given grid data.- Parameters:
_griddata
- the data
-
-
Method Details
-
xToIndex
public int xToIndex(double x) Gets closest index from the given x world coordinate. -
yToIndex
public int yToIndex(double y) Gets closest index from the given y world coordinate. -
indexToX
public double indexToX(int i) Gets the x coordinate for the given index. -
indexToY
public double indexToY(int i) Gets the y coordinate for the given index. -
setAll
Sets the data to new values. The grid is resized to fit the new data if needed. -
setAll
Sets the values and the scale. The grid is resized to fit the new data if needed. -
getGridData
Gets the GridData object.- Specified by:
getGridData
in interfacePlot2D
- Returns:
- GridData
-
setGridData
Sets the data storage to the given value.- Specified by:
setGridData
in interfacePlot2D
- Parameters:
_griddata
- the new data storage
-
setIndexes
public void setIndexes(int[] indexes) Sets the indexes for the data components that will be plotted. Indexes determine the postion of the amplitude, x-component, and y-component in the data array.- Specified by:
setIndexes
in interfacePlot2D
- Parameters:
indexes
- the sample-component indexes
-
setArrowType
public void setArrowType(int type) Sets this vector field to draw vectors with filled shafts and arrowheads.- Parameters:
type
-
-
setPaletteType
public void setPaletteType(int mode) Sets the type of palette. Palette types are defined in the ColorMapper class and include: SPECTRUM, BLACK, RED, and BLUE. The default type is SPECTRUM.- Specified by:
setPaletteType
in interfacePlot2D
- Parameters:
mode
-
-
setColorPalette
Sets the colors that will be used between the floor and ceiling values. Not implemented in this class.- Specified by:
setColorPalette
in interfacePlot2D
- Parameters:
colors
-
-
setVisible
public void setVisible(boolean vis) Sets this vector field to be visible. Drawing will be disabled if visible is false.- Specified by:
setVisible
in interfacePlot2D
- Parameters:
vis
-
-
setShowGridLines
public void setShowGridLines(boolean showGrid) Outlines the data grid's boundaries.- Specified by:
setShowGridLines
in interfacePlot2D
- Parameters:
showGrid
-
-
setGridLineColor
Sets the color for grid line boundaries- Specified by:
setGridLineColor
in interfacePlot2D
- Parameters:
c
-
-
draw
Draws this vector field in the given drawing panel. -
scaleArrowLenghToGrid
public void scaleArrowLenghToGrid(boolean scaleToGrid) Sets the autoscale flag for the arrow length.- Parameters:
scaleToGrid
-
-
setAutoscaleZ
public void setAutoscaleZ(boolean isAutoscale, double floor, double ceil) Sets the autoscale flag and the floor and ceiling values. If autoscaling is true, then the min and max values of z are set using the data. If autoscaling is false, then floor and ceiling values become the max and min. Values below min map to the first color; values above max map to the last color.- Specified by:
setAutoscaleZ
in interfacePlot2D
- Parameters:
isAutoscale
-floor
-ceil
-
-
setSymmetricZ
public void setSymmetricZ(boolean symmetric) Forces the z-scale to be symmetric about zero. Not applicable in vector map because vector amplitude is always positive- Specified by:
setSymmetricZ
in interfacePlot2D
- Parameters:
symmetric
-
-
isSymmetricZ
public boolean isSymmetricZ()Gets the symmetric z flag.- Specified by:
isSymmetricZ
in interfacePlot2D
-
isAutoscaleZ
public boolean isAutoscaleZ()Gets the autoscale flag for z.- Specified by:
isAutoscaleZ
in interfacePlot2D
- Returns:
- boolean
-
getFloor
public double getFloor()Gets the floor for scaling the z data. -
getCeiling
public double getCeiling()Gets the ceiling for scaling the z data.- Specified by:
getCeiling
in interfacePlot2D
- Returns:
- double
-
setFloorCeilColor
Sets the floor and ceiling colors. Not implemented in this class.- Specified by:
setFloorCeilColor
in interfacePlot2D
- Parameters:
floorColor
-ceilColor
-
-
showLegend
Shows how values map to colors.- Specified by:
showLegend
in interfacePlot2D
-
update
public void update()Updates the vector field using the data array. -
setExpandedZ
public void setExpandedZ(boolean expanded, double expansionFactor) Expands the z scale so as to enhance values close to zero.- Specified by:
setExpandedZ
in interfacePlot2D
- Parameters:
expanded
- booleanexpansionFactor
- double
-
getXMin
public double getXMin()Description copied from interface:Measurable
Gets the minimum x needed to draw this object.- Specified by:
getXMin
in interfaceMeasurable
- Returns:
- minimum
-
getXMax
public double getXMax()Description copied from interface:Measurable
Gets the maximum x needed to draw this object.- Specified by:
getXMax
in interfaceMeasurable
- Returns:
- maximum
-
getYMin
public double getYMin()Description copied from interface:Measurable
Gets the minimum y needed to draw this object.- Specified by:
getYMin
in interfaceMeasurable
- Returns:
- minimum
-
getYMax
public double getYMax()Description copied from interface:Measurable
Gets the maximum y needed to draw this object.- Specified by:
getYMax
in interfaceMeasurable
- Returns:
- minimum
-
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 interfaceMeasurable
- Returns:
- true if min/max values are valid
-
getLoader
Gets an XML.ObjectLoader to save and load data for this program.- Returns:
- the object loader
-