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, other_shapes): pnt = CheckGeom.to_point(pnt) if not pnt: raise TypeError('Invalid point type provided.') v = Vertex.by_point(pnt) super(DistancePointToShapes, self).__init__(v, other_shapes)
def __init__(self, shape, pnt): pnt = CheckGeom.to_point(pnt) if shape.shape_type not in [Shape.FACE, Shape.SHELL]: raise RuntimeError('Invalid shape for creating half-space.') self._solid = Solid( BRepPrimAPI_MakeHalfSpace(shape.object, pnt).Solid())
def __init__(self, pnts, close=False): builder = BRepBuilderAPI_MakePolygon() for p in pnts: p = CheckGeom.to_point(p) builder.Add(p) if close: builder.Close() self._w = Wire(builder.Wire())
def by_point(pnt): """ Create a vertex by a point. :param point_like pnt: The point. :return: The vertex. :rtype: afem.topology.entities.Vertex """ pnt = CheckGeom.to_point(pnt) return Vertex(BRepBuilderAPI_MakeVertex(pnt).Vertex())
def perform(self, pnt, tol=1.0e-7): """ Perform the classification with the point and tolerance. :param point_like pnt: The point. :param float tol: The tolerance. :return: None. """ pnt = CheckGeom.to_point(pnt) self._tool.Perform(pnt, tol)
def set_enforced_nodes(self, shapes, pnts): """ Set enforced nodes on shapes. :param list(afem.topology.entities.Shape) shapes: List of shapes. :param list(point_like) pnts: List of points for enforced nodes. :return: None. """ pnts = [CheckGeom.to_point(p) for p in pnts] shapes_ = [s.object for s in shapes] self._hyp.SetEnforcedNodes(shapes_, pnts)
def add_pnt(self, pnt): """ Add a point to the bounding box. :param point_like pnt: The point. :return: None. :raise TypeError: If *pnt* cannot be converted to a point. """ pnt = CheckGeom.to_point(pnt) if not pnt: msg = 'Invalid point type provided.' raise TypeError(msg) self.Add(pnt)
def query_point(self, p0, distance_upper_bound=inf): """ Find the intersection result nearest to the provided point. :param point_like p0: Point to search from. :param float distance_upper_bound: Return only results within this distance. :return: Distance to nearest intersection result and its index (d, i). Returns (None, None) if no results are available. :rtype: tuple """ if not self.success: return None, None p0 = CheckGeom.to_point(p0) d, i = self._kdt.query(p0.xyz, 1, 0., 2, distance_upper_bound) return d, i
def by_points(pnts, close=False): """ Create polygonal wire by connecting points. :param collections.Sequence(point_like) pnts: The ordered points. :param bool close: Option to close the wire. :return: The new wire. :rtype: afem.topology.entities.Wire """ builder = BRepBuilderAPI_MakePolygon() for p in pnts: p = CheckGeom.to_point(p) builder.Add(p) if close: builder.Close() return Wire(builder.Wire())
def is_pnt_out(self, pnt): """ Check to see if the point is outside the bounding box. :param point_like pnt: The point. :return: *True* if outside, *False* if not. :rtype: bool :raise TypeError: If *pnt* cannot be converted to a point. """ pnt = CheckGeom.to_point(pnt) if not pnt: msg = 'Invalid point type provided.' raise TypeError(msg) return self.IsOut(pnt)
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, 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, origin=(0., 0., 0.), radius=1.): origin = CheckGeom.to_point(origin) self._builder = BRepPrimAPI_MakeSphere(origin, radius)
def __init__(self, p1, p2): p1 = CheckGeom.to_point(p1) p2 = CheckGeom.to_point(p2) super(BoxBy2Points, self).__init__(p1, p2)