/** * Point4.java * * author: Keith McGuigan * * The Point4 class represents a world-coordinate point. * The class provides 4 fields, x, y, z and w. All are public. * The Point4 class can represent a point or a vector. * * Edit history * 11/4/98 rdb Added cross and dot methods * 11/3/98 rdb Added Point4( Point4 ) constructor * Added toString */ //package matrix; public class Point4 extends Object { public double x; public double y; public double z; public double w; /** * Constructors to create the vector */ public Point4() { this(0,0,0,1); } public Point4(double _x, double _y, double _z) { this(_x, _y, _z, 1); } public Point4( Point4 p ) { this(p.x, p.y, p.z); w = p.w; } public Point4(double _x, double _y, double _z, double _w) { super(); x = _x; y = _y; z = _z; w = _w; } /** * Assigns a new value to this point. * @param p A vector to be copied */ public void assign(Point4 p) { x = p.x; y = p.y; z = p.z; w = p.w; } /** * Converts instance to a string * @return A string that represents the vector */ public String toString() { return new String("<" + x + ", " + y + ", " + z + ", " + w + ">"); } //------------------- cross product ---------------------------- // return this X p // public Point4 cross( Point4 p ) { return new Point4( y * p.z - z * p.y, z * p.x - x * p.z, x * p.y - y * p.x ); } //------------------- dot product ---------------------------- // return this dot p (ignoring w component) // public double dot( Point4 p ) { return x * p.x + y * p.y + z * p.z; } }