def __init__(self, crv1, crv2, tol=1.0e-10): adp_crv1 = AdaptorCurve.to_adaptor(crv1) adp_crv2 = AdaptorCurve.to_adaptor(crv2) tool = Extrema_ExtCC(adp_crv1.object, adp_crv2.object, tol, tol) if not tool.IsDone(): msg = 'Extrema between two curves 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]
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 __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)
def __init__(self, shape, n, d1=None, d2=None, shape1=None, shape2=None): adp_crv = AdaptorCurve.to_adaptor(shape) u1 = adp_crv.u1 u2 = adp_crv.u2 # Adjust parameters of start/end shapes are provided if isinstance(shape1, Shape): u1 = _param_on_adp_crv(adp_crv, shape, shape1) if isinstance(shape2, Shape): u2 = _param_on_adp_crv(adp_crv, shape, shape2) super(PointsAlongShapeByNumber, self).__init__(adp_crv, n, u1, u2, d1, d2)
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
def _reloft_wing_surface(srf, tol): """ Attempt to reloft an OpenVSP wing surface which was not split to achieve higher continuity. """ logger.info('\tAttempting to reloft the surface...') # Gather isocurves at each section, tessellate, and approximate crvs = [] for u in srf.uknots: c0 = srf.u_iso(u) adp_crv = AdaptorCurve.to_adaptor(c0) tool = GCPnts_QuasiUniformDeflection(adp_crv.object, tol) if not tool.IsDone(): logger.info('\tTessellation failed. Using original surface.') return srf pnts = [c0.eval(tool.Parameter(i)) for i in range(1, tool.NbPoints() + 1)] c = NurbsCurveByApprox(pnts, tol=tol, continuity=Geometry.C1).curve crvs.append(c) return NurbsSurfaceByInterp(crvs, 1).surface
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)
def __init__(self, shape, maxd, ref_pln=None, d1=None, d2=None, shape1=None, shape2=None, nmin=0): adp_crv = AdaptorCurve.to_adaptor(shape) u1 = adp_crv.u1 u2 = adp_crv.u2 # Adjust parameters of start/end shapes are provided if isinstance(shape1, Shape): u1 = _param_on_adp_crv(adp_crv, shape, shape1) if isinstance(shape2, Shape): u2 = _param_on_adp_crv(adp_crv, shape, shape2) super(PlanesAlongShapeByDistance, self).__init__(adp_crv, maxd, ref_pln, u1, u2, d1, d2, nmin)
def __init__(self, shape, ds, tol=1.0e-7): adp_crv = AdaptorCurve.to_adaptor(shape) u0 = adp_crv.u1 super(PointAlongShape, self).__init__(adp_crv, u0, ds, tol)