1use crate::Triangle;
2use mini_math::{Point, Vector3};
3
4#[derive(Debug)]
6pub struct Plane {
7 pub normal: Vector3,
9 pub d: f32,
11}
12
13impl Plane {
14 pub fn new(normal: Vector3, d: f32) -> Self {
16 Self { normal, d }
17 }
18
19 pub fn from_points(p0: Point, p1: Point, p2: Point) -> Self {
21 let normal = -(p1 - p0).cross(p2 - p0).normalized();
22 let d = Vector3::from(p0).dot(normal);
23 Self { normal, d }
24 }
25
26 pub fn from_point_and_normal(p: Point, normal: Vector3) -> Self {
28 Self {
29 normal,
30 d: Vector3::from(p).dot(normal),
31 }
32 }
33}
34
35impl From<&Triangle> for Plane {
36 fn from(t: &Triangle) -> Self {
37 Plane::from_points(t.a, t.b, t.c)
38 }
39}