/* I am a point in three space. I am represented in cylindrical coordinates, but I can answer my cartesian coordinates. I am immutable. */ public class ThreeDPoint { /* Create a 3D point from the given cylindrical coordinates. */ public ThreeDPoint (double rr, double th, double xx) { r = rr; theta = th; x = xx; } /* Cylindrical accessors. */ public double getR () {return r;} public double getTheta () {return theta;} public double getX () {return x;} /* Cartesian Y accessor. */ public double getY () { return r * Math.cos (theta); } /* Cartesian Z accessor. */ public double getZ () { return r * Math.sin (theta); } /* Euclidean distance metric. */ public double distanceTo (ThreeDPoint p) { double dx = getX () - p.getX (); double dy = getY () - p.getY (); double dz = getZ () - p.getZ (); return Math.sqrt (dx * dx + dy * dy + dz * dz); } private double r; /*radius. distance from axis of cylinder.*/ private double theta; /* angle in radians relative to some arbitrary angle */ private double x; /* distance along the axis from some arbitrary point */ }