src/org/math/plot/render/Projection3D.java

00001 package org.math.plot.render;
00002 
00008 public class Projection3D extends Projection {
00009 
00010         protected double theta;
00011 
00012         protected double phi;
00013 
00014         // protected boolean useRoundTrigonometry = false;
00015 
00016         public Projection3D(AWTDrawer _draw) {
00017                 super(_draw);
00018                 theta = Math.PI / 4;
00019                 phi = Math.PI / 4;
00020                 initBaseCoordsProjection();
00021         }
00022 
00023         protected double[] baseCoordsScreenProjectionRatio(double[] xyz) {
00024                 double factor = 1.7;
00025                 double[] sC = new double[2];
00026                 sC[0] = 0.5
00027                                 + (cos(theta)
00028                                                 * ((xyz[1] - (draw.canvas.base.roundXmax[1] + draw.canvas.base.roundXmin[1]) / 2) / (draw.canvas.base.roundXmax[1] - draw.canvas.base.roundXmin[1])) - sin(theta)
00029                                                 * ((xyz[0] - (draw.canvas.base.roundXmax[0] + draw.canvas.base.roundXmin[0]) / 2) / (draw.canvas.base.roundXmax[0] - draw.canvas.base.roundXmin[0])))
00030                                 / factor;
00031                 sC[1] = 0.5
00032                                 + (cos(phi)
00033                                                 * ((xyz[2] - (draw.canvas.base.roundXmax[2] + draw.canvas.base.roundXmin[2]) / 2) / (draw.canvas.base.roundXmax[2] - draw.canvas.base.roundXmin[2]))
00034                                                 - sin(phi)
00035                                                 * cos(theta)
00036                                                 * ((xyz[0] - (draw.canvas.base.roundXmax[0] + draw.canvas.base.roundXmin[0]) / 2) / (draw.canvas.base.roundXmax[0] - draw.canvas.base.roundXmin[0])) - sin(phi)
00037                                                 * sin(theta)
00038                                                 * ((xyz[1] - (draw.canvas.base.roundXmax[1] + draw.canvas.base.roundXmin[1]) / 2) / (draw.canvas.base.roundXmax[1] - draw.canvas.base.roundXmin[1])))
00039                                 / factor;
00040                 // System.out.println("Theta = " + theta + " Phi = " + phi);
00041                 // System.out.println("(" + xyz[0] +"," + xyz[1] +"," + xyz[2] + ") ->
00042                 // (" + sC[0] + "," + sC[1] + ")");
00043                 return sC;
00044         }
00045 
00046         // TODO test efficiceny of an approximation of cos and sin fuctions.
00047         
00048         /*
00049          * private final static double _2PI = 2 * Math.PI;
00050          * 
00051          * private final static int N = 100;
00052          * 
00053          * private final static double[] COS =
00054          * DoubleArray.f(DoubleArray.increment(N, 0, 2 * Math.PI / (N - 1)), new
00055          * Function() { public double f(double x) { return Math.cos(x); } });
00056          * 
00057          * private final static double[] SIN =
00058          * DoubleArray.f(DoubleArray.increment(N, 0, 2 * Math.PI / (N - 1)), new
00059          * Function() { public double f(double x) { return Math.sin(x); } });
00060          */
00061         private double cos(double x) {
00062                 return Math.cos(x);
00063         }
00064 
00065         private double sin(double x) {
00066                 return Math.sin(x);
00067         }
00068 
00069         public void setView(double _theta, double _phi) {
00070                 theta = _theta;
00071                 phi = _phi;
00072                 initBaseCoordsProjection();
00073         }
00074 
00075         public void rotate(int[] screenTranslation, int[] dimension) {
00076                 theta = theta - ((double) screenTranslation[0]) / 100;
00077                 phi = phi + ((double) screenTranslation[1]) / 100;
00078                 initBaseCoordsProjection();
00079         }
00080 
00081 }

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