From c0d4db9ae48eb9a8d83603ce448bfbd5bfa44d87 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 31 Jul 2024 19:55:35 +0200 Subject: [PATCH] Add `Triangle::point_from_barycentric_coords` --- crates/fj-math/src/triangle.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/crates/fj-math/src/triangle.rs b/crates/fj-math/src/triangle.rs index 92cbbb0fa..2780a410d 100644 --- a/crates/fj-math/src/triangle.rs +++ b/crates/fj-math/src/triangle.rs @@ -43,6 +43,16 @@ impl Triangle { area > Scalar::default_epsilon() } + /// Convert barycentric coordinates to a point + pub fn point_from_barycentric_coords( + &self, + [wa, wb, wc]: [Scalar; 3], + ) -> Point { + 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