Interpolated Plot, Explicación
Description
Primero se deben incluye los import:
```
import org.opensourcephysics.display.DrawingFrame;
import org.opensourcephysics.display.DrawingPanel;
import org.opensourcephysics.display.PlottingPanel;
import org.opensourcephysics.display2d.InterpolatedPlot;
```
El cosntructor primero debe crear el panel
```
DrawingPanel plottingPanel = new PlottingPanel("x", "y", "Interpolated Plot");
DrawingFrame frame = new DrawingFrame(plottingPanel);
```
para luego la matriz con la información a ser desplegada
```
int SIZE = 100;
double[][] data = new double[SIZE][SIZE];
InterpolatedPlot plot = new InterpolatedPlot();
plot.setAll(data, -1.5, 1.5, -1.5, 1.5);
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[i][j] = Math.exp(-(x*x+y*y));
}
}
plot.setAll(data);
plottingPanel.addDrawable(plot);
```
y finalmente colgar la grafica del marco
```
frame.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
```
La fuente se puede bajar de [Interpol.java](Interpol.java)
ID:(7541, 0)
Interpolated Plot, Código
Description
import org.opensourcephysics.display.DrawingFrame;
import org.opensourcephysics.display.DrawingPanel;
import org.opensourcephysics.display.PlottingPanel;
import org.opensourcephysics.display2d.InterpolatedPlot;
public class Interpol {
Interpol(){
DrawingPanel plottingPanel = new PlottingPanel("x", "y", "Interpolated Plot");
DrawingFrame frame = new DrawingFrame(plottingPanel);
int SIZE = 100;
double[][] data = new double[SIZE][SIZE];
InterpolatedPlot plot = new InterpolatedPlot();
plot.setAll(data, -1.5, 1.5, -1.5, 1.5);
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[i][j] = Math.exp(-(x*x+y*y));
}
}
plot.setAll(data);
plottingPanel.addDrawable(plot);
frame.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
ID:(7542, 0)