-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlane.java
65 lines (53 loc) · 2.07 KB
/
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
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
// class to define a 2d plane in 3d space
// currently only implemented to make a floor to make a more complete scene
public class Plane{
// define some stuff about the plane
double c = 0;
double x = 0;
double y = 0;
double z = 0;
// this angle must be the normal vectors direction
double[] angleOfNorm = {0, 90};
double[] normalVector = Scene.angleToVector(angleOfNorm[0], angleOfNorm[1]);
boolean reflectivity = false;
double size = 0;
public Plane(double x_, double y_, double z_, double size_, double c_){
x = x_;
y = y_;
z = z_;
c = c_;
size = size_;
}
public Plane(double x_, double y_, double z_, double c_, double yaw, double pitch, double size_, boolean reflectivity_){
x = x_;
y = y_;
z = z_;
c = c_;
size = size_;
reflectivity = reflectivity_;
angleOfNorm[0] = yaw;
angleOfNorm[1] = pitch;
normalVector = Scene.angleToVector(angleOfNorm[0], angleOfNorm[1]);
}
public double distTo(double x_, double y_, double z_){
// since it is a 2d plane just pass through to signed dist
return signedDistTo(x_, y_, z_);
}
public double signedDistTo(double x_, double y_, double z_){
// formula for dist of a infinant plane
double dist = Scene.dotProduct(normalVector[0], normalVector[1], normalVector[2], x_-x, y_-y, z_-z);
// limit the size of the plane by doing some trig
double hypotonusDist = Math.sqrt(Math.pow(x_-x, 2) + Math.pow(y_-y, 2) + Math.pow(z_-z, 2));
double distFromOrigin = Math.sqrt(Math.pow(hypotonusDist, 2) - Math.pow(dist, 2));
// apply the limit to the dist
double distConfined = distFromOrigin - size;
if (distConfined < 0){
distConfined = 0;
}
dist = Math.sqrt(Math.pow(dist, 2) + Math.pow(distConfined, 2));
return dist;
}
public double[] getNormalVector(){
return normalVector;
}
}