/Users/lyon/j4p/src/graphics/raytracers/tracer/geometry/Ray3d.java

1    package graphics.raytracers.tracer.geometry; 
2     
3     
4    final public class Ray3d { 
5        private Vector3d startPoint, direction; 
6     
7        public Ray3d(Vector3d pnt, Vector3d dir) { 
8            startPoint = new Vector3d(pnt.getX(), pnt.getY(), pnt.getZ()); 
9            direction = new Vector3d(dir.getX(), dir.getY(), dir.getZ()); 
10           direction.normalize(); 
11       } 
12    
13       public Ray3d() { 
14           startPoint = new Vector3d(); 
15           direction = new Vector3d(); 
16       } 
17    
18       public Vector3d point(double t) { 
19           return new Vector3d(startPoint.getX() + direction.getX() * t, startPoint.getY() + direction.getY() * t, startPoint.getZ() + direction.getZ() * t); 
20       } 
21    
22       public String toString() { 
23           return "{" + startPoint.toString() + " -> " + direction.toString() + "}"; 
24       } 
25    
26       public Vector3d getStartPoint() { 
27           return startPoint; 
28       } 
29    
30       public void setStartPoint(Vector3d p) { 
31           startPoint = p; 
32       } 
33    
34       public Vector3d getDirection() { 
35           return direction; 
36       } 
37    
38       public void setDirection(Vector3d d) { 
39           direction = d; 
40       } 
41   } 
42