-
Notifications
You must be signed in to change notification settings - Fork 0
/
Plane.java
34 lines (27 loc) · 912 Bytes
/
Plane.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
public class Plane {
private Vector3 normalVector;
private double d;
public Plane(double a, double b, double c, double d) {
this(new Vector3(a, b, c), d);
}
public Plane(Vector3 normalVector, Vector3 point) {
this(normalVector, -normalVector.dot(point));
}
public Plane(Vector3 firstVector, Vector3 secondVector, Vector3 point) {
this(firstVector.cross(secondVector), point);
}
public Plane(Vector3 normalVector, double d) {
this.normalVector = normalVector;
this.d = d;
}
public double compare(Vector3 point) {
return normalVector.dot(point) + d;
}
public Vector3 intersection(Vector3 directionVector, Vector3 point) {
double t = -(normalVector.dot(point) + d) / normalVector.dot(directionVector);
return point.add(directionVector.multiply(t));
}
public String toString() {
return "Plane: " + normalVector + " * x + " + d + " = 0";
}
}