/
Ray.java
70 lines (62 loc) · 1.04 KB
/
Ray.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/** Class to represent a ray
* @author Carol Chen
*/
public class Ray {
public Vector A;
public Vector B;
public double time;
/**
* Empty constructor
*/
public Ray () { }
/**
* @param a point a
* @param b point b
*/
public Ray (Vector a, Vector b) {
A = a;
B = b;
}
/**
* @param a point a
* @param b point b
* @param t value t (controls "magnitude")
*/
public Ray (Vector a, Vector b, double t) {
A = a;
B = b;
time = t;
}
/**
* @return origin (point a) of the vector
*/
public Vector origin() {
return A;
}
/**
* @return direction vector (point b)
*/
public Vector direction() {
return B;
}
/**
* @return get time of ray's existance
*/
public double time() {
return time;
}
/**
* @return get the point at t value
*/
public Vector pointAt(double t) {
return A.add(B.multiply(t));
}
/**
* @param r Ray to set ray to
*/
public void set(Ray r) {
A = r.A;
B = r.B;
time = r.time();
}
}