/**************************************************************************** ** Point3d.java - model a 3d point or vector ** Copyright (C) 1996 Ray L. Ewbank ** ** This program is free software; you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation; either version 2 of the License, or ** (at your option) any later version. ** ** This program is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. ** ** You should have received a copy of the GNU General Public License ** along with this program; if not, write to the Free Software ** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. ** ** Direct any questions concerning this piece of Software to: ** ** Ray L. Ewbank ** 29-02 Arlington Road ** Woburn, MA 01801 ** ** (617) 938-7137 ** ** ewbank@gis.net **************************************************************************** */ class Point3d { public double x; public double y; public double z; public Point3d() {x=y=z=0.0;} public Point3d(double inx, double iny, double inz) {x=inx;y=iny;z=inz;} public void normalize() { double r = x*x+y*y+z*z; if (r > 0.0) { r = Math.sqrt(r); x/=r; y/=r; z/=r; } } public double dot(Point3d p) { return x*p.x+y*p.y+z*p.z; } public Point3d crossp(Point3d p) { Point3d t = new Point3d(); t.x = y*p.z - z*p.y; t.y = z*p.x - x*p.z; t.z = x*p.y - y*p.x; return t; } public Point3d subtract(Point3d p) { Point3d t = new Point3d(); t.x = x-p.x; t.y = y-p.y; t.z = z-p.z; return t; } public int hashCode() { return (int)(x*27) ^ (int)(y*31) ^ (int)(z*37); } public boolean equals(Object obj) { if (obj instanceof Point3d) { Point3d p = (Point3d)obj; return (x==p.x) && (y==p.y) && (z==p.z); } return false; } public String toString() { return getClass().getName()+ "[x=" + x + ",y=" + y + ",z=" + z + "]"; } }