From ec8ad21cb58efd49262b55a7bb7f6ddb80109513 Mon Sep 17 00:00:00 2001 From: Alessio Quaglino Date: Fri, 24 Oct 2025 03:42:03 -0700 Subject: [PATCH] Normalize triangle coordinates such that their sum rather their norm is one. This ensures that at e.g. the barycenter of the triangle each vertex has weight 1/3, as one would expect with barycentric coordinates, rather than 1/sqrt(3). This makes it consistent to the finite element interpolation used in the passive elastic forces. PiperOrigin-RevId: 823458736 Change-Id: Ia5c02cba186a80612de38402f791695c33e991ab --- src/engine/engine_core_constraint.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/engine/engine_core_constraint.c b/src/engine/engine_core_constraint.c index 7ebacddb..fc024029 100644 --- a/src/engine/engine_core_constraint.c +++ b/src/engine/engine_core_constraint.c @@ -172,7 +172,11 @@ static int mj_elemBodyWeight(const mjModel* m, const mjData* d, int f, int e, in } // normalize weights - mju_normalize(weight, dim+1); + mjtNum sum = mju_sum(weight, dim+1); + if (sum < mjMINVAL) { + mjERROR("element body weight sum < mjMINVAL"); + } + mju_scl(weight, weight, 1.0/sum, dim+1); return dim+1; }