package uk.org.floop.epq3d; public class Point3D { public double x; public double y; public double z; public Point3D(double _x, double _y, double _z){ x = _x; y = _y; z = _z; } public Point3D(double[] xyz){ if(xyz.length != 3){ throw new RuntimeException("Point3D cannot be instantiated from != 3 points " + "(attempted: " + xyz.length + ")"); } x = xyz[0]; y = xyz[1]; z = xyz[2]; } public Point3D(){ x = 0; y = 0; z = 0; } public void set(double[] _new){ x = _new[0]; y = _new[1]; z = _new[2]; } public void translate(Point3D trVec){ x += trVec.x; y += trVec.y; z += trVec.z; } public Point2D project(double fpdis, int scrX, int scrY){ return new Point2D( scrX - (int)(scrX*0.5*((fpdis*y)/(z) + 1)), (int)(scrX*0.5*((fpdis*x)/(z) + ((double)scrY/(double)scrX))) ); } public void projectOn(double fpdis, int scrX, int scrY, Point2D point){ // this is a mess of random fixes because none of my coordinates are correct. :( // sorry point.x = scrX - (int)(scrX*0.5*((fpdis*y)/(z) + 1)); point.y = (int)(scrX*0.5*((fpdis*x)/(z) + ((double)scrY/(double)scrX))); } public double[] get(){ return new double[]{x, y, z}; } }