1 package edu.berkeley.qfat.geom;
2 import javax.media.opengl.*;
3 import javax.media.opengl.glu.*;
5 /** point in 3-space; immutable */
6 public final class Point implements HasBoundingBox {
7 public final float x, y, z;
8 public Point(double x, double y, double z) { this((float)x, (float)y, (float)z); }
9 public Point(float x, float y, float z) { this.x = x; this.y = y; this.z = z; }
11 public static final Point ORIGIN = new Point(0,0,0);
13 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)); }
15 public Vec minus(Point p) { return new Vec(x-p.x, y-p.y, z-p.z); }
16 public Point plus(Vec v) { return new Point(x+v.x, y+v.y, z+v.z); }
18 public void glVertex(GL gl) { gl.glVertex3f(x, y, z); }
20 public String toString() { return "("+x+","+y+","+z+")"; }
22 public boolean equals(Object o) { return o!=null && (o instanceof Point) && ((Point)o).x==x && ((Point)o).y==y && ((Point)o).z==z; }
23 public int hashCode() { return Float.floatToIntBits(x) ^ Float.floatToIntBits(y) ^ Float.floatToIntBits(z); }
25 public float getMaxX() { return x; }
26 public float getMinX() { return x; }
27 public float getMaxY() { return y; }
28 public float getMinY() { return y; }
29 public float getMaxZ() { return z; }
30 public float getMinZ() { return z; }