def __init__(self, pnt, crv, tol=1.0e-10): adp_crv = AdaptorCurve.to_adaptor(crv) tool = Extrema_ExtPC(pnt, adp_crv.object, tol) if not tool.IsDone(): msg = 'Extrema between point and curve 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 = ext_pnt.Parameter() pi = CheckGeom.to_point(gp_pnt) results.append((di, ui, 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 _distance_point_to_curve(point, curve): """ Find the minimum distance between a point and a curve. """ # OCC extrema. adp_crv = AdaptorCurve.to_adaptor(curve) ext_pc = Extrema_ExtPC(point, adp_crv.object) if not ext_pc.IsDone(): return None # Find the minimum result. n_ext = ext_pc.NbExt() for i in range(1, n_ext + 1): if ext_pc.IsMin(i): d = ext_pc.SquareDistance(i) return sqrt(d) return None