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
use crate::Triangle;
use mini_math::{Point, Vector3};
#[derive(Debug)]
pub struct Plane {
pub normal: Vector3,
pub d: f32,
}
impl Plane {
pub fn new(normal: Vector3, d: f32) -> Self {
Self { normal, d }
}
pub fn from_points(p0: Point, p1: Point, p2: Point) -> Self {
let normal = -(p1 - p0).cross(p2 - p0).normalized();
let d = Vector3::from(p0).dot(normal);
Self { normal, d }
}
pub fn from_point_and_normal(p: Point, normal: Vector3) -> Self {
Self {
normal,
d: Vector3::from(p).dot(normal),
}
}
}
impl From<&Triangle> for Plane {
fn from(t: &Triangle) -> Self {
Plane::from_points(t.a, t.b, t.c)
}
}