Skip to content

Commit 94a3cfd

Browse files
phkahlerwhitequark
authored andcommitted
Fix SSurface::EdgeNormalsWithinSurface() to handle non-orthogonal u,v derivatives correctly.
1 parent 225f82a commit 94a3cfd

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/srf/boolean.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -379,11 +379,17 @@ void SSurface::EdgeNormalsWithinSurface(Point2d auv, Point2d buv,
379379
enxyz = (ab.Cross(*surfn)).WithMagnitude(SS.ChordTolMm());
380380
// And based on that, compute the edge's inner normal in uv space. This
381381
// vector is perpendicular to the edge in xyz, but not necessarily in uv.
382-
Vector tu, tv;
382+
Vector tu, tv, tx, ty;
383383
TangentsAt(muv.x, muv.y, &tu, &tv);
384+
Vector n = tu.Cross(tv);
385+
// since tu and tv may not be orthogonal, use y in place of v, x in place of u.
386+
// |y| = |v|sin(theta) where theta is the angle between tu and tv.
387+
ty = n.Cross(tu).ScaledBy(1.0/tu.MagSquared());
388+
tx = tv.Cross(n).ScaledBy(1.0/tv.MagSquared());
389+
384390
Point2d enuv;
385-
enuv.x = enxyz.Dot(tu) / tu.MagSquared();
386-
enuv.y = enxyz.Dot(tv) / tv.MagSquared();
391+
enuv.x = enxyz.Dot(tx) / tx.MagSquared();
392+
enuv.y = enxyz.Dot(ty) / ty.MagSquared();
387393

388394
// Compute the inner and outer normals of this edge (within the srf),
389395
// in xyz space. These are not necessarily antiparallel, if the

0 commit comments

Comments
 (0)