Avoid zero tangnet vectors on degenerate NURBS edges. Fixes #652

pull/749/head
phkahler 2020-10-17 14:05:29 -04:00
parent e42aa0fac4
commit 408128a138
2 changed files with 8 additions and 2 deletions

View File

@ -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);
@ -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(tv->Equals(Vector::From(0,0,0)) && retry)
TangentsAt(u+(0.5-u)*0.00001, v, tu, tv, false);
if(tu->Equals(Vector::From(0,0,0)) && retry)
TangentsAt(u, v+(0.5-v)*0.00001, tu, tv, false);
}
Vector SSurface::NormalAt(Point2d puv) const {

View File

@ -335,7 +335,7 @@ public:
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;