MCPcopy Create free account
hub / github.com/OpenSourcePhysics/osp / VectorPlot

Class VectorPlot

src/org/opensourcephysics/display2d/VectorPlot.java:31–588  ·  view source on GitHub ↗

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. @author Wolfgang Christian @version 1.0

Source from the content-addressed store, hash-verified

29 * @version 1.0
30 */
31public class VectorPlot implements Plot2D {
32 public static final int STROKEDARROW = 0;
33 public static final int FILLEDARROW = 1;
34 private GeneralPath vectorpath;
35 private int arrowType = STROKEDARROW; // draw the arrow with a solid arrowhead
36 private boolean visible = true;
37 private GridData griddata;
38 private boolean autoscaleZ = true;
39 private boolean scaleArrowToGrid = true;
40 private VectorColorMapper colorMap;
41 private int ampIndex = 0; // amplitude index
42 private int aIndex = 1; // x componnet index
43 private int bIndex = 2; // y component index
44 private double xmin, xmax, ymin, ymax;
45 Grid grid;
46
47 /**
48 * Constructs a VectorPlot without data.
49 */
50 public VectorPlot() {
51 this(null);
52 }
53
54 /**
55 * Constructs a VectorPlot that renders the given grid data.
56 *
57 * @param _griddata the data
58 */
59 public VectorPlot(GridData _griddata) {
60 griddata = _griddata;
61 colorMap = new VectorColorMapper(256, 1.0);
62 if(griddata==null) {
63 return;
64 }
65 grid = (griddata.isCellData()) ? new Grid(griddata.getNx(), griddata.getNy()) : new Grid(griddata.getNx()-1, griddata.getNy()-1);
66 grid.setColor(Color.lightGray);
67 grid.setVisible(false);
68 update();
69 }
70
71 /**
72 * Gets closest index from the given x world coordinate.
73 *
74 * @param x double the coordinate
75 * @return int the index
76 */
77 @Override
78public int xToIndex(double x) {
79 return griddata.xToIndex(x);
80 }
81
82 /**
83 * Gets closest index from the given y world coordinate.
84 *
85 * @param y double the coordinate
86 * @return int the index
87 */
88 @Override

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected