Skip to content

Commit 6e747ac

Browse files
authored
Merge pull request #2452 from hannobraun/triangle
Add `Triangle::point_from_barycentric_coords`
2 parents b787d99 + c0d4db9 commit 6e747ac

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

crates/fj-math/src/triangle.rs

+10
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,16 @@ impl<const D: usize> Triangle<D> {
4343
area > Scalar::default_epsilon()
4444
}
4545

46+
/// Convert barycentric coordinates to a point
47+
pub fn point_from_barycentric_coords(
48+
&self,
49+
[wa, wb, wc]: [Scalar; 3],
50+
) -> Point<D> {
51+
let [a, b, c] = self.points;
52+
let coords = a.coords * wa + b.coords * wb + c.coords * wc;
53+
Point { coords }
54+
}
55+
4656
/// Normalize the triangle
4757
///
4858
/// Returns a new `Triangle` instance with the same points, but the points

0 commit comments

Comments
 (0)