/** 3D ray * @author: Phil Gage */ class Ray { Point origin; Vector3 direction; Ray () { this.origin = new Point (); this.direction = new Vector3 (); } Ray (Point origin, Vector3 direction) { this.origin = new Point (origin); this.direction = new Vector3 (direction); } // Reflect incident ray using normal static Vector3 reflect (Vector3 incident, Vector3 normal) { Vector3 r = new Vector3 (); double n = Vector3.dot(normal,normal); double i = Vector3.dot(normal,incident); r.x = incident.x-(2.0*i/n)*normal.x; r.y = incident.y-(2.0*i/n)*normal.y; r.z = incident.z-(2.0*i/n)*normal.z; return r; } // Refract incident ray using normal //tbd // Project along (normalized) ray to get point Point extrapolate (double distance, Point p) { double m = this.direction.magnitude(); p.x = origin.x + distance*direction.x/m; p.y = origin.y + distance*direction.y/m; p.z = origin.z + distance*direction.z/m; return p; } public String toString () { return "Ray dir x=" + direction.x + " y=" + direction.y + " z=" + direction.z; } }