Merge pull request #2452 from hannobraun/triangle

Add `Triangle::point_from_barycentric_coords`
This commit is contained in:
Hanno Braun 2024-08-13 19:12:01 +02:00 committed by GitHub
commit 6e747acd3a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -43,6 +43,16 @@ impl<const D: usize> Triangle<D> {
area > Scalar::default_epsilon()
}
/// Convert barycentric coordinates to a point
pub fn point_from_barycentric_coords(
&self,
[wa, wb, wc]: [Scalar; 3],
) -> Point<D> {
let [a, b, c] = self.points;
let coords = a.coords * wa + b.coords * wb + c.coords * wc;
Point { coords }
}
/// Normalize the triangle
///
/// Returns a new `Triangle` instance with the same points, but the points