src/org/math/plot/plots/VectorLayerPlot.java

00001 package org.math.plot.plots;
00002 
00003 import java.awt.*;
00004 
00005 import javax.swing.*;
00006 
00007 import org.math.plot.*;
00008 import org.math.plot.render.*;
00009 import org.math.plot.utils.*;
00010 
00017 public class VectorLayerPlot extends LayerPlot {
00018 
00019         public static int RADIUS = 5;
00020 
00021         double[][] V;
00022 
00026         public VectorLayerPlot(Plot p, double[][] v) {
00027                 super("Vector of " + p.name, p);
00028                 if (v != null) {
00029                         Array.checkRowDimension(v, p.getData().length);
00030                         Array.checkColumnDimension(v, p.getData()[0].length);
00031                 }
00032                 V = v;
00033 
00034         }
00035 
00036         @Override
00037         public void setData(double[][] v) {
00038                 V = v;
00039         }
00040 
00041         @Override
00042         public double[][] getData() {
00043                 return V;
00044         }
00045 
00046         public void plot(AbstractDrawer draw, Color c) {
00047                 if (!plot.visible)
00048                         return;
00049 
00050                 draw.setColor(c);
00051 
00052                 draw.setLineType(AbstractDrawer.CONTINOUS_LINE);
00053 
00054                 for (int i = 0; i < plot.getData().length; i++) {
00055                         double[] d = Array.getRowCopy(plot.getData(), i);
00056                         for (int j = 0; j < d.length; j++) {
00057                                 d[j] += V[i][j];
00058                         }
00059                         draw.drawLine(plot.getData()[i], d);
00060                         //TODO: draw arrow at position d
00061 
00062                 }
00063 
00064         }
00065 
00066         public static void main(String[] args) {
00067                 Plot2DPanel p2 = new Plot2DPanel();
00068                 double[][] XYZ = new double[100][2];
00069                 double[][] dXYZ = new double[100][2];
00070 
00071                 for (int j = 0; j < XYZ.length; j++) {
00072                         XYZ[j][0] = Math.random()*10;
00073                         XYZ[j][1] = Math.random()*10;
00074                         dXYZ[j][0] = 1.0/Math.sqrt(1+Math.log(XYZ[j][0])*Math.log(XYZ[j][0]));
00075                         dXYZ[j][1] = Math.log(XYZ[j][0])/Math.sqrt(1+Math.log(XYZ[j][0])*Math.log(XYZ[j][0]));
00076                 }
00077                 p2.addScatterPlot("toto", XYZ);
00078 
00079                 p2.addVectortoPlot(0, dXYZ);
00080                 new FrameView(p2).setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
00081         }
00082 }

Generated on Wed Sep 5 21:44:02 2007 for jmathplot by  doxygen 1.5.1