From 6b8af9cf83851c075c6c9514b1deaa931c2b19a4 Mon Sep 17 00:00:00 2001 From: Thomas Guillermo Albers Raviola Date: Fri, 16 Jan 2026 23:02:32 +0100 Subject: Initial commit --- 09-september/tomcat/math/math_util.c | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 09-september/tomcat/math/math_util.c (limited to '09-september/tomcat/math/math_util.c') diff --git a/09-september/tomcat/math/math_util.c b/09-september/tomcat/math/math_util.c new file mode 100644 index 0000000..1285f3d --- /dev/null +++ b/09-september/tomcat/math/math_util.c @@ -0,0 +1,10 @@ +#include "math_util.h" + +float baryCentric(Vec3 *p1, Vec3 *p2, Vec3 *p3, Vec2 *pos) +{ + float det = (p2->z - p3->z) * (p1->x - p3->x) + (p3->x - p2->x) * (p1->z - p3->z); + float l1 = ((p2->z - p3->z) * (pos->x - p3->x) + (p3->x - p2->x) * (pos->y - p3->z)) / det; + float l2 = ((p3->z - p1->z) * (pos->x - p3->x) + (p1->x - p3->x) * (pos->y - p3->z)) / det; + float l3 = 1.0f - l1 - l2; + return l1 * p1->y + l2 * p2->y + l3 * p3->y; +} -- cgit v1.2.3