/Users/lyon/j4p/src/bookExamples/ch26Graphics/draw2d/Ray2d.java
|
1 package bookExamples.ch26Graphics.draw2d;
2
3
4 public class Ray2d {
5 Vec2d p; // origin
6 Vec2d d; // direction
7 int count;
8 double t = 0;
9 Paintable object;
10
11 Vec2d vecOnLine(double _t) {
12 t = _t;
13 return d.linearComb(t, p);
14 }
15
16 public Ray2d(Line2d l) {
17 count = 0;
18 p = new Vec2d(l.x1, l.y1);
19 d = new Vec2d(l.x2 - l.x1, l.y2 - l.y1);
20 d.normalize();
21 }
22
23 public Ray2d(Vec2d _p, Vec2d _d) {
24 p = new Vec2d(_p);
25 d = new Vec2d(_d);
26 }
27
28 public String toString() {
29 return "Origin=" + p + "\ndirection=" + d;
30 }
31 }
32
33