def __init__(self, pnt, srf, tol=1.0e-10): adp_srf = AdaptorSurface.to_adaptor(srf) tool = Extrema_ExtPS(pnt, adp_srf.object, tol, tol) if not tool.IsDone(): msg = 'Extrema between point and surface failed.' raise RuntimeError(msg) self._nsol = tool.NbExt() results = [] for i in range(1, self._nsol + 1): di = sqrt(tool.SquareDistance(i)) ext_pnt = tool.Point(i) gp_pnt = ext_pnt.Value() ui, vi = ext_pnt.Parameter() pi = CheckGeom.to_point(gp_pnt) results.append((di, (ui, vi), pi)) results.sort(key=lambda tup: tup[0]) self._dmin = results[0][0] self._dmax = results[-1][0] self._dist = [row[0] for row in results] self._prms = [row[1] for row in results] self._pnts = [row[2] for row in results]
def __init__(self, pnt, srf, direction=None, update=False, tol=1.0e-7): super(ProjectPointToSurface, self).__init__() pnt = CheckGeom.to_point(pnt) direction = CheckGeom.to_direction(direction) adp_srf = AdaptorSurface.to_adaptor(srf) self._results = [] if not direction: ext = Extrema_ExtPS(pnt, adp_srf.object, tol, tol) npts = ext.NbExt() for i in range(1, npts + 1): pos = ext.Point(i) ui, vi = pos.Parameter(0., 0.) pi = adp_srf.eval(ui, vi) di = sqrt(ext.SquareDistance(i)) self._results.append([pi, (ui, vi), di]) else: # Use minimum distance between line and surface to project point # along a direction. line = Line.by_direction(pnt, direction) adp_crv = AdaptorCurve.to_adaptor(line) ext = Extrema_ExtCS(adp_crv.object, adp_srf.object, tol, tol) npts = ext.NbExt() for i in range(1, npts + 1): poc, pos = Extrema_POnCurv(), Extrema_POnSurf() ext.Points(i, poc, pos) ui, vi = pos.Parameter(0., 0.) pi = adp_srf.eval(ui, vi) di = sqrt(ext.SquareDistance(i)) self._results.append([pi, (ui, vi), di]) # Sort by distance and return. if self._results: self._results.sort(key=lambda lst: lst[2]) if update: pnt.set_xyz(self.nearest_point)