class Point{ float x; float y; float z; public Point(){ this(0, 0); } public Point(float x, float y){ this(x, y, 0); } public Point(float x, float y, float z){ this.x = x; this.y = y; this.z = z; } public Point copy(){ return new Point(this.x, this.y, this.z); } public void setTo(Point p){ this.setTo(p.x, p.y, p.z); } public void setTo(float x, float y, float z){ this.x = x; this.y = y; this.z = z; } // opperators public Point addVector(Vector v){ return new Point(this.x + v.x, this.y + v.y, this.z + v.z); } public void addScaledVector(float s, Vector v){ this.x += s * v.x; this.y += s * v.y; this.z += s * v.z; } public Point subVector(Vector v){ return new Point(this.x - v.x, this.y - v.y, this.z - v.z); } public Point subPoint(Point p){ return new Point(this.x - p.x, this.y - p.y, this.z - p.z); } // methods public Vector vecTo(Point p){ return new Vector(p.x - this.x, p.y - this.y, p.z - this.z); } public float distanceTo(Point p){ return sqrt(sq(p.x - this.x) + sq(p.y - this.y) + sq(p.z - this.z)); } public Point midPoint(Point p){ return new Point((this.x + p.x) / 2, (this.y + p.y) / 2, (this.z + p.z) / 2); } public Point interp(float s, Point p){ Vector unit = this.vecTo(p); return new Point(this.x + (unit.x * s), this.y + (unit.y * s), this.z + (unit.z * s)); } } class Vector{ float x; float y; float z; public Vector(){ this(0, 0); } public Vector(float x, float y){ this(x, y, 0); } public Vector(float x, float y, float z){ this.x = x; this.y = y; this.z = z; } public Vector copy(){ return new Vector(this.x, this.y, this.z); } public void scale(float s){ this.x *= s; this.y *= s; this.z *= s; } public float norm(){ return sqrt(sq(this.x) + sq(this.y) + sq(this.z)); } public Vector unit(){ float n = this.norm(); Vector result = this.copy(); if(n > 0.0000001){ result.scale(1 / n); } return result; } public Vector average(Vector B){ return new Vector((this.x + B.x) / 2.0, (this.y + B.y) / 2.0, (this.z + B.z) / 2.0); } // operations public float dot(Vector V){ return (this.x * V.x) + (this.y * V.y) + (this.z * V.z); } public Vector cross(Vector V){ return(new Vector(this.y * V.z - this.z * V.y, this.z * V.x - this.x * V.z, this.x * V.y - this.y * V.x)); } } // Some fun general stuff public Vector triangleNormal(Point A, Point B, Point C){ return (A.vecTo(B)).cross(A.vecTo(C)); } public float mixedProduct(Vector A, Vector B, Vector C){ return (A.cross(B)).dot(C); }