예제 #1
0
파일: distance.py 프로젝트: trelau/AFEM
    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]
예제 #2
0
    def __init__(self, pnt, crv, direction=None, update=False):
        super(ProjectPointToCurve, self).__init__()

        pnt = CheckGeom.to_point(pnt)
        direction = CheckGeom.to_direction(direction)
        adp_crv = AdaptorCurve.to_adaptor(crv)
        self._results = []

        if not direction:
            ext = Extrema_ExtPC(pnt, adp_crv.object)
            npts = ext.NbExt()
            for i in range(1, npts + 1):
                poc = ext.Point(i)
                ui = poc.Parameter()
                pi = adp_crv.eval(ui)
                di = sqrt(ext.SquareDistance(i))
                self._results.append([pi, ui, di])
        else:
            # Use minimum distance between line and curve to project point
            # along a direction.
            line = Line.by_direction(pnt, direction)
            adp_crv2 = AdaptorCurve.to_adaptor(line)
            ext = Extrema_ExtCC(adp_crv.object, adp_crv2.object)
            npts = ext.NbExt()
            for i in range(1, npts + 1):
                poc1, poc2 = Extrema_POnCurv(), Extrema_POnCurv()
                ext.Points(i, poc1, poc2)
                ui = poc1.Parameter()
                pi = adp_crv.eval(ui)
                di = sqrt(ext.SquareDistance(i))
                self._results.append([pi, ui, 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)
예제 #3
0
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