{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Point3D

# Point3D - package raytracer.utility public class Point3D...

This preview shows pages 1–3. Sign up to view the full content.

package raytracer.utility; public class Point3D { public double x, y, z; // --------------------------------------------- default constructor public Point3D(){ x = y = z = 0; } // --------------------------------------------- constructor public Point3D(double a){ x = y = z = a; } // --------------------------------------------- constructor public Point3D(double a, double b, double c){ x = a; y = b; z = c; } // --------------------------------------------- copy constructor public Point3D(Point3D p){ this.x = p.x; this.y = p.y; this.z = p.z; } // ---------------------------------------------------------- assignment operator /** assignment operation * @param p point */ public void set (Point3D p) { if (this != p) { x = p.x; y = p.y; z = p.z; } } // --------------------------------------------- distance // distance between two points public double distance(Point3D p) { return (Math.sqrt( (x - p.x) * (x - p.x) + (y - p.y) * (y - p.y) + (z - p.z) * (z - p.z) )); } // -------------------------------------------------------------- operator- // unary minus public Point3D minus() { return new Point3D(-x, -y, -z); }

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
// -------------------------------------------------------------- operator- // the vector that joins two points public Vector3D subtract(Point3D p){ return new Vector3D(x - p.x,y - p.y,z - p.z); } // -------------------------------------------------------------- operator+ // addition of a vector to a point that returns a new point public Point3D add(Vector3D v) { return new Point3D(x + v.x, y + v.y, z + v.z); } // -------------------------------------------------------------- operator- // subtraction of a vector from a point that returns a new point public Point3D subtract(Vector3D v) { return new Point3D(x - v.x, y - v.y, z - v.z); } // -------------------------------------------------------------- operator*
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 4

Point3D - package raytracer.utility public class Point3D...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online