Пример #1
0
    def __init__(self, crv, srf, tol=1.0e-10):
        adp_crv = AdaptorCurve.to_adaptor(crv)
        adp_srf = AdaptorSurface.to_adaptor(srf)
        tool = Extrema_ExtCS(adp_crv.object, adp_srf.object, tol, tol)

        if not tool.IsDone():
            msg = 'Extrema between curve and surface failed.'
            raise RuntimeError(msg)

        self._nsol = tool.NbExt()
        self._parallel = tool.IsParallel()
        results = []
        for i in range(1, self._nsol + 1):
            di = sqrt(tool.SquareDistance(i))
            gp_pnt1, gp_pnt2 = tool.Points(i)
            p1 = CheckGeom.to_point(gp_pnt1)
            p2 = CheckGeom.to_point(gp_pnt2)
            results.append((di, p1, p2))

        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._pnts1 = [row[1] for row in results]
        self._pnts2 = [row[2] for row in results]
Пример #2
0
    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)