star-3d

Surface structuring for efficient 3D geometric queries
git clone git://git.meso-star.fr/star-3d.git
Log | Files | Refs | README | LICENSE

commit e0a2def7efa54942325497ef71680500c812c3c7
parent a8d1e50b58b70de5b71e3aaefb6288d1b2102d6c
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Fri,  4 Oct 2019 15:47:52 +0200

Fix an issue in the closest_point_triangle routine

Diffstat:
Msrc/s3d_scene_view_point_query.c | 10++++++----
1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/src/s3d_scene_view_point_query.c b/src/s3d_scene_view_point_query.c @@ -62,7 +62,7 @@ closest_point_triangle float ab[3], ac[3], ap[3], bp[3], cp[3]; float d1, d2, d3, d4, d5, d6; float va, vb, vc; - float triangle_area; + float rcp_triangle_area; float v, w; ASSERT(p && a && b && c && closest_pt && uv); @@ -137,14 +137,16 @@ closest_point_triangle /* The closest point lies in the triangle: compute its barycentric * coordinates */ - triangle_area = va + vb + vc; - v = vb * triangle_area; - w = vc * triangle_area; + rcp_triangle_area = 1.f / (va + vb + vc); + v = vb * rcp_triangle_area; + w = vc * rcp_triangle_area; /* Save the uv barycentric coordinates */ uv[0] = 1.f - v - w; uv[1] = v; + ASSERT(eq_epsf(uv[0] + uv[1] + w, 1.f, 1.e-4f)); + /* Use the barycentric coordinates to compute the world space position of the * closest point onto the triangle */ closest_pt[0] = a[0] + v*ab[0] + w*ac[0];