diff --git a/dsc.h b/dsc.h index 55a6d02..cb5727c 100644 --- a/dsc.h +++ b/dsc.h @@ -67,6 +67,7 @@ public: Vector Minus(Vector b); Vector Negated(void); Vector Cross(Vector b); + double DirectionCosineWith(Vector b); double Dot(Vector b); Vector Normal(int which); Vector RotatedAbout(Vector orig, Vector axis, double theta); diff --git a/srf/boolean.cpp b/srf/boolean.cpp index a27451f..858d1c1 100644 --- a/srf/boolean.cpp +++ b/srf/boolean.cpp @@ -322,10 +322,6 @@ void SSurface::EdgeNormalsWithinSurface(Point2d auv, Point2d buv, Point2d enuv; enuv.x = enxyz.Dot(tu) / tu.MagSquared(); enuv.y = enxyz.Dot(tv) / tv.MagSquared(); - // Don't let the magnitude get too tiny at small chord tolerances; we - // will otherwise have numerical problems subtracting nearly-equal - // numbers. - enuv = enuv.WithMagnitude(0.01); // Compute the inner and outer normals of this edge (within the srf), // in xyz space. These are not necessarily antiparallel, if the diff --git a/srf/raycast.cpp b/srf/raycast.cpp index 8229197..4fde6e3 100644 --- a/srf/raycast.cpp +++ b/srf/raycast.cpp @@ -7,8 +7,9 @@ //----------------------------------------------------------------------------- #include "solvespace.h" -// Dot product tolerance for perpendicular. -const double SShell::DOTP_TOL = 1e-3; +// Dot product tolerance for perpendicular; this is on the direction cosine, +// so it's about 0.001 degrees. +const double SShell::DOTP_TOL = 1e-5; extern int FLAG; @@ -394,7 +395,7 @@ void SShell::AllPointsIntersecting(Vector a, Vector b, int SShell::ClassifyRegion(Vector edge_n, Vector inter_surf_n, Vector edge_surf_n) { - double dot = inter_surf_n.Dot(edge_n); + double dot = inter_surf_n.DirectionCosineWith(edge_n); if(fabs(dot) < DOTP_TOL) { // The edge's surface and the edge-on-face surface // are coincident. Test the edge's surface normal @@ -466,7 +467,7 @@ bool SShell::ClassifyEdge(int *indir, int *outdir, // TODO, make this use the appropriate curved normals double dotp[2]; for(int i = 0; i < 2; i++) { - dotp[i] = edge_n_out.Dot(inter_surf_n[i]); + dotp[i] = edge_n_out.DirectionCosineWith(inter_surf_n[i]); } if(fabs(dotp[1]) < DOTP_TOL) { diff --git a/util.cpp b/util.cpp index 0df2d76..e066dc9 100644 --- a/util.cpp +++ b/util.cpp @@ -362,6 +362,12 @@ double Vector::Dot(Vector b) { return (x*b.x + y*b.y + z*b.z); } +double Vector::DirectionCosineWith(Vector b) { + Vector a = this->WithMagnitude(1); + b = b.WithMagnitude(1); + return a.Dot(b); +} + Vector Vector::Normal(int which) { Vector n;