From 94a3cfdeb74aa3cbfd91ffe26ffa57c63a1094b2 Mon Sep 17 00:00:00 2001 From: phkahler <14852918+phkahler@users.noreply.github.com> Date: Mon, 1 Jun 2020 21:10:25 -0400 Subject: [PATCH] Fix SSurface::EdgeNormalsWithinSurface() to handle non-orthogonal u,v derivatives correctly. --- src/srf/boolean.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/srf/boolean.cpp b/src/srf/boolean.cpp index 6f1041c..cb72cd8 100644 --- a/src/srf/boolean.cpp +++ b/src/srf/boolean.cpp @@ -379,11 +379,17 @@ void SSurface::EdgeNormalsWithinSurface(Point2d auv, Point2d buv, enxyz = (ab.Cross(*surfn)).WithMagnitude(SS.ChordTolMm()); // And based on that, compute the edge's inner normal in uv space. This // vector is perpendicular to the edge in xyz, but not necessarily in uv. - Vector tu, tv; + Vector tu, tv, tx, ty; TangentsAt(muv.x, muv.y, &tu, &tv); + Vector n = tu.Cross(tv); + // since tu and tv may not be orthogonal, use y in place of v, x in place of u. + // |y| = |v|sin(theta) where theta is the angle between tu and tv. + ty = n.Cross(tu).ScaledBy(1.0/tu.MagSquared()); + tx = tv.Cross(n).ScaledBy(1.0/tv.MagSquared()); + Point2d enuv; - enuv.x = enxyz.Dot(tu) / tu.MagSquared(); - enuv.y = enxyz.Dot(tv) / tv.MagSquared(); + enuv.x = enxyz.Dot(tx) / tx.MagSquared(); + enuv.y = enxyz.Dot(ty) / ty.MagSquared(); // Compute the inner and outer normals of this edge (within the srf), // in xyz space. These are not necessarily antiparallel, if the