Eigen::Vector3d ClosingBoundary::commonBoundaryPoint2 (ON_NurbsSurface &n1, ON_NurbsSurface &n2, Eigen::Vector2d ¶ms1, Eigen::Vector2d ¶ms2, Eigen::Vector3d start, unsigned nsteps, double &error, double accuracy) { Eigen::Vector3d current = start; double error1 (DBL_MAX); double error2 (DBL_MAX); Eigen::Vector3d p1, p2, tu1, tu2, tv1, tv2; params1 = FittingSurface::findClosestElementMidPoint (n1, current); params2 = FittingSurface::findClosestElementMidPoint (n2, current); params1 = FittingSurface::inverseMapping (n1, current, params1, error1, p1, tu1, tv1, nsteps, accuracy, true); params2 = FittingSurface::inverseMapping (n2, current, params2, error2, p2, tu2, tv2, nsteps, accuracy, true); for (unsigned i = 0; i < nsteps; i++) { params1 = FittingSurface::inverseMapping (n1, current, params1, error1, p1, tu1, tv1, nsteps, accuracy, true); params2 = FittingSurface::inverseMapping (n2, current, params2, error2, p2, tu2, tv2, nsteps, accuracy, true); // params1 = ntools1.inverseMappingBoundary(current, error1, p1, tu1, tv1, 10, 1e-2, true); // params2 = ntools2.inverseMappingBoundary(current, error2, p2, tu2, tv2, 10, 1e-2, true); // dbgWin.AddLine3D(current(0), current(1), current(2), p1(0), p1(1), p1(2), 0, 0, 255); // dbgWin.AddLine3D(current(0), current(1), current(2), p2(0), p2(1), p2(2), 0, 0, 255); // dbgWin.AddPoint3D(current(0), current(1), current(2), 0, 0, 255, 3); // current = (p1 + p2) * 0.5; Eigen::Vector3d n1 = tu1.cross (tv1); n1.normalize (); Eigen::Vector3d n2 = tu2.cross (tv2); n2.normalize (); Eigen::Vector3d l1 = (p2 - n1 * n1.dot (p2 - p1)) - p1; l1.normalize (); Eigen::Vector3d l2 = (p1 - n2 * n2.dot (p1 - p2)) - p2; l2.normalize (); // dbgWin.AddLine3D(p1(0), p1(1), p1(2), p1(0) + l1(0), p1(1) + l1(1), p1(2) + l1(2), 255, 0, 0); // dbgWin.AddLine3D(p2(0), p2(1), p2(2), p2(0) + l2(0), p2(1) + l2(1), p2(2) + l2(2), 255, 0, 0); Eigen::Vector3d P, Q; getLineDistance (p1, l1, p2, l2, P, Q); current = (P + Q) * 0.5; } error = 0.5 * (error1 + error2); // dbgWin.AddPoint3D(current(0), current(1), current(2), 255, 0, 255, 5); // dbgWin.Update(); return current; }
Eigen::Vector3d ClosingBoundary::commonBoundaryPoint3 (ON_NurbsSurface &n1, ON_NurbsSurface &n2, Eigen::Vector2d ¶ms1, Eigen::Vector2d ¶ms2, Eigen::Vector3d start, unsigned nsteps, double &error, double accuracy) { Eigen::Vector3d current = start; double error1 (DBL_MAX); double error2 (DBL_MAX); Eigen::Vector3d p1, p2, tu1, tu2, tv1, tv2; params1 = FittingSurface::findClosestElementMidPoint (n1, current); params2 = FittingSurface::findClosestElementMidPoint (n2, current); params1 = FittingSurface::inverseMapping (n1, current, params1, error1, p1, tu1, tv1, nsteps, accuracy, true); params2 = FittingSurface::inverseMapping (n2, current, params2, error2, p2, tu2, tv2, nsteps, accuracy, true); for (unsigned i = 0; i < nsteps; i++) { params1 = FittingSurface::inverseMapping (n1, current, params1, error1, p1, tu1, tv1, nsteps, accuracy, true); params2 = FittingSurface::inverseMapping (n2, current, params2, error2, p2, tu2, tv2, nsteps, accuracy, true); // dbgWin.AddLine3D(current(0), current(1), current(2), p1(0), p1(1), p1(2), 0, 0, 255); // dbgWin.AddLine3D(current(0), current(1), current(2), p2(0), p2(1), p2(2), 0, 0, 255); // dbgWin.AddPoint3D(current(0), current(1), current(2), 0, 0, 255, 3); Eigen::Vector3d n1 = tu1.cross (tv1); n1.normalize (); double d1 = n1.dot (p1); Eigen::Vector3d n2 = tu2.cross (tv2); n2.normalize (); double d2 = n2.dot (p2); Eigen::Vector3d n3 = (p1 - current).cross (p2 - current); n3.normalize (); double d3 = n3.dot (current); current = intersectPlanes (n1, d1, n2, d2, n3, d3); } // dbgWin.AddPoint3D(current(0), current(1), current(2), 255, 0, 255, 5); // dbgWin.Update(); error = 0.5 * (error1 + error2); return current; }