Triangle functionality

This commit is contained in:
2026-01-16 12:28:04 +11:00
parent b224160aad
commit edc1485449
3 changed files with 31 additions and 3 deletions
+7
View File
@@ -7,6 +7,7 @@ pub struct Point2D {
pub x: f64,
pub y: f64
}
#[derive(Debug, Clone, Copy)]
pub struct Point3D {
pub x: f64, pub y: f64, pub z: f64
@@ -118,4 +119,10 @@ impl Point2D {
+ f64::powf(p2.y.max(p1.y) - p1.y.min(p2.y), 2.0)) as f64,
)
}
pub fn gradient(self, p2: &Point2D) -> f64 {
let p1 = self;
(p2.y - p1.y) / (p2.x - p1.x)
}
}