-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRay.java
More file actions
64 lines (54 loc) · 1.48 KB
/
Copy pathRay.java
File metadata and controls
64 lines (54 loc) · 1.48 KB
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
package primitives;
public class Ray extends Vector {
private Point_3D _p0;
// ***************** Constructors ********************** //
/**
* construct ray with vector and 3D point
*
* @param vector
* - vector
* @param point
* - point 3D
*/
public Ray(Vector vector, Point_3D point) {
super(vector.normalize());
_p0 = point;
}
// ***************** Getters/Setters ********************** //
public Point_3D p0() {
return _p0;
}
public Vector direction() {
return this;
}
/***
* finds a ray sends from the same point in a different angle
* @param normal vector normal to the direction vector
* @param scalar
* @return a ray sends from the same point in a different angle
*/
public Ray nearbyRay(Vector normal1, Vector normal2, double scalar1, double scalar2) {
Ray result = new Ray(this, _p0);
normal1 = normal1.normalize();
normal1 = normal1.scale(scalar1);
normal2 = normal2.normalize();
normal2 = normal2.scale(scalar2);
result.add(normal1);
result.add(normal2);
return result;
}
// ***************** Operations ******************** //
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (!(obj instanceof Ray))
return false;
Ray other = (Ray) obj;
return super.equals(obj) && _p0.equals(other._p0);
}
@Override
public String toString() {
return super.toString().replaceFirst("]", "] point=" + _p0);
}
}