-
-
Notifications
You must be signed in to change notification settings - Fork 87
Expand file tree
/
Copy pathPlane.ts
More file actions
30 lines (25 loc) · 594 Bytes
/
Plane.ts
File metadata and controls
30 lines (25 loc) · 594 Bytes
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
import Vec3 from "../math/Vec3";
export default class Plane {
public x: number;
public y: number;
public z: number;
public w: number;
public constructor(x = 0, y = 1, z = 0, w = 0) {
this.x = x;
this.y = y;
this.z = z;
this.w = w;
}
public normalize(): Plane {
const length = Math.sqrt(this.x ** 2 + this.y ** 2 + this.z ** 2);
this.x /= length;
this.y /= length;
this.z /= length;
this.w /= length;
return this;
}
public distanceToPoint(point: Vec3): number {
const normal = new Vec3(this.x, this.y, this.z);
return Vec3.dot(normal, point) + this.w;
}
}