1 package edu.berkeley.qfat.geom;
2 import javax.media.opengl.*;
4 /** point in 3-space; immutable */
5 public final class Point implements HasBoundingBox {
6 public final float x, y, z;
7 public Point(double x, double y, double z) { this((float)x, (float)y, (float)z); }
8 public Point(float x, float y, float z) { this.x = x; this.y = y; this.z = z; }
10 public static final Point ORIGIN = new Point(0,0,0);
12 public float distance(Point p) { return (float)Math.sqrt((x-p.x)*(x-p.x)+(y-p.y)*(y-p.y)+(z-p.z)*(z-p.z)); }
14 // FIXME: this should be eliminated; wrong order
15 public Point times(Matrix m) { return m.times(this); }
17 public Vec minus(Point p) { return new Vec(x-p.x, y-p.y, z-p.z); }
18 public Point plus(Vec v) { return new Point(x+v.x, y+v.y, z+v.z); }
20 public void glVertex(GL gl) { gl.glVertex3f(x, y, z); }
22 public String toString() { return "("+x+","+y+","+z+")"; }
24 public boolean equals(Object o) { return o!=null && (o instanceof Point) && ((Point)o).x==x && ((Point)o).y==y && ((Point)o).z==z; }
25 public int hashCode() { return Float.floatToIntBits(x) ^ Float.floatToIntBits(y) ^ Float.floatToIntBits(z); }
27 public float getMaxX() { return x; }
28 public float getMinX() { return x; }
29 public float getMaxY() { return y; }
30 public float getMinY() { return y; }
31 public float getMaxZ() { return z; }
32 public float getMinZ() { return z; }