Skip to content

Commit

Permalink
Avoid zero tangnet vectors on degenerate NURBS edges. Fixes solvespac…
Browse files Browse the repository at this point in the history
  • Loading branch information
phkahler committed Oct 17, 2020
1 parent 91684fe commit ec7da60
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
8 changes: 7 additions & 1 deletion src/srf/ratpoly.cpp
Expand Up @@ -332,7 +332,7 @@ Vector SSurface::PointAt(double u, double v) const {
return num;
}

void SSurface::TangentsAt(double u, double v, Vector *tu, Vector *tv) const {
void SSurface::TangentsAt(double u, double v, Vector *tu, Vector *tv, bool retry) const {
Vector num = Vector::From(0, 0, 0),
num_u = Vector::From(0, 0, 0),
num_v = Vector::From(0, 0, 0);
Expand Down Expand Up @@ -364,6 +364,12 @@ void SSurface::TangentsAt(double u, double v, Vector *tu, Vector *tv) const {

*tv = ((num_v.ScaledBy(den)).Minus(num.ScaledBy(den_v)));
*tv = tv->ScaledBy(1.0/(den*den));

// Tangent is zero at sungularities like the north pole. Move away a bit and retry.
if(tu->Equals(Vector::From(0,0,0)) && retry)
TangentsAt(u, v+(0.5-v)*LENGTH_EPS, tu, tv, false);
if(tv->Equals(Vector::From(0,0,0)) && retry)
TangentsAt(u+(0.5-u)*LENGTH_EPS, v, tu, tv, false);
}

Vector SSurface::NormalAt(Point2d puv) const {
Expand Down
2 changes: 1 addition & 1 deletion src/srf/surface.h
Expand Up @@ -335,7 +335,7 @@ class SSurface {
void PointOnCurve(const SBezier *curve, double *up, double *vp);
Vector PointAt(double u, double v) const;
Vector PointAt(Point2d puv) const;
void TangentsAt(double u, double v, Vector *tu, Vector *tv) const;
void TangentsAt(double u, double v, Vector *tu, Vector *tv, bool retry=true) const;
Vector NormalAt(Point2d puv) const;
Vector NormalAt(double u, double v) const;
bool LineEntirelyOutsideBbox(Vector a, Vector b, bool asSegment) const;
Expand Down

0 comments on commit ec7da60

Please sign in to comment.