Campo de Vectores, Explicación
Description
Primero se debe importar las clases necesarias
```
import org.opensourcephysics.display.DrawingFrame;
import org.opensourcephysics.display.DrawingPanel;
import org.opensourcephysics.display2d.VectorPlot;
```
Dentro del constructor primero se define el panel:
```
DrawingPanel drawingPanel = new DrawingPanel();
DrawingFrame frame = new DrawingFrame(drawingPanel);
drawingPanel.setSquareAspect(true);
```
luego la matriz de los datos a ser dibujada
```
int SIZE = 20;
double[][][] data = new double[2][SIZE][SIZE];
VectorPlot plot = new VectorPlot();
plot.setAll(data, -1, 1, -1, 1);
for(int i = 0;i < SIZE;i++){
double x = plot.indexToX(i);
for(int j = 0;j < SIZE;j++){
double y = plot.indexToY(j);
data[0][i][j] = -y;
data[1][i][j] = x;
}
}
plot.setAll(data);
drawingPanel.addDrawable(plot);
```
y finalmente colgada de la forma
```
frame.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
```
La fuente del constructor puede bajase de
[Vector.java](Vector.java)
ID:(7534, 0)
Campo de Vectores, Código
Description
![constructor](structure/lego-blue.jpg)
Código del constructor
```
import org.opensourcephysics.display.DrawingFrame;
import org.opensourcephysics.display.DrawingPanel;
import org.opensourcephysics.display2d.VectorPlot;
public class Vector {
Vector(){
DrawingPanel drawingPanel = new DrawingPanel();
DrawingFrame frame = new DrawingFrame(drawingPanel);
drawingPanel.setSquareAspect(true);
int SIZE = 20;
double[][][] data = new double[2][SIZE][SIZE];
VectorPlot plot = new VectorPlot();
plot.setAll(data, -1, 1, -1, 1);
for(int i = 0;i < SIZE;i++){
double x = plot.indexToX(i);
for(int j = 0;j < SIZE;j++){
double y = plot.indexToY(j);
data[0][i][j] = -y;
data[1][i][j] = x;
}
}
plot.setAll(data);
drawingPanel.addDrawable(plot);
frame.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
```
ID:(7535, 0)