Ejemplo n.º 1
0
def trimedge(lbound, ubound, occedge):
    """
    This function trims the OCCedge according to the specified lower and upper bound.
 
    Parameters
    ----------
    lbound : float
        The lower bound of the OCCedge.
        
    ubound : float
        The upper bound of the OCCedge.
        
    occedge : OCCedge
        The edge to be trimmed.

    Returns
    -------
    trimmed edge : OCCedge
        The trimmed OCCedge.
    """
    adaptor = BRepAdaptor_Curve(occedge)
    tr = Geom_TrimmedCurve(adaptor.Curve().Curve(), lbound, ubound)
    tr.SetTrim(lbound, ubound)
    bspline_handle = geomconvert_CurveToBSplineCurve(tr.BasisCurve())
    tr_edge = BRepBuilderAPI_MakeEdge(bspline_handle)

    return tr_edge.Edge()
Ejemplo n.º 2
0
 def trim(self, lbound, ubound):
     '''
     trim the curve
     @param lbound:
     @param ubound:
     '''
     a, b = sorted([lbound, ubound])
     tr = Geom_TrimmedCurve(self.adaptor.Curve().Curve(), a, b).GetHandle()
     return Edge(make_edge(tr))
Ejemplo n.º 3
0
def getPntsEdgesFacesIntersect(edgesShape, facesShape):
    pnts = []
    faces = getShapeItems(facesShape, TopAbs_FACE)
    edges = getShapeItems(edgesShape, TopAbs_EDGE)
    for edge in edges:
        for face in faces:
            curve3 = BRep_Tool.Curve(edge)
            curve = Geom_TrimmedCurve(curve3[0],curve3[1],curve3[2])
            surface = BRep_Tool.Surface(face)
            pntsToAdd = getPntsCurveSurfaceIntersect(curve, surface)
            pnts += pntsToAdd
    return pnts
Ejemplo n.º 4
0
def trim_wire(wire, shapeLimit1, shapeLimit2, periodic=False):
    '''return the trimmed wire that lies between `shapeLimit1`
    and `shapeLimit2`
    returns TopoDS_Edge
    '''
    adap = to_adaptor_3d(wire)
    bspl = adap.BSpline()
    if periodic:
        spl = bspl.GetObject()
        if spl.IsClosed():
            spl.SetPeriodic()
        else:
            warnings.warn('the wire to be trimmed is not closed, hence cannot be made periodic')
    p1 = project_point_on_curve(bspl, shapeLimit1)[0]
    p2 = project_point_on_curve(bspl, shapeLimit2)[0]
    a, b = sorted([p1, p2])
    tr = Geom_TrimmedCurve(bspl, a, b).GetHandle()
    return make_edge(tr)
Ejemplo n.º 5
0
    def face_rotate(self, face=TopoDS_Face(), axs=gp_Ax1()):
        plan = self.pln_on_face(face)
        plan_axs = plan.Position()
        self.display.DisplayShape(plan_axs.Location())

        v0 = dir_to_vec(self.tmp_axis.Direction())
        v1 = dir_to_vec(plan_axs.Direction())
        print(v0.Dot(v1))

        lin_vec = gp_Vec(axs.Location(), plan_axs.Location())
        edg_circl = Geom_Circle(
            gp_Circ(
                gp_Ax2(axs.Location(), axs.Direction(), vec_to_dir(lin_vec)),
                5))
        rim_u0, rim_u1 = edg_circl.FirstParameter(), edg_circl.LastParameter()
        rim_p0 = edg_circl.Value(rim_u0)

        pln_angle = self.tmp_axis.Angle(plan_axs)
        ref_angle = self.tmp_axis.Direction().AngleWithRef(
            plan_axs.Direction(), axs.Direction())
        print(np.rad2deg(pln_angle), np.rad2deg(ref_angle))

        rim_u2 = -ref_angle
        rim_p2 = edg_circl.Value(rim_u2)
        rim_angle = Geom_TrimmedCurve(edg_circl, rim_u0, rim_u2)

        trf = gp_Trsf()
        #trf.SetRotation(axs, 2*np.pi - ref_angle)
        if np.abs(ref_angle) >= np.pi / 2:
            trf.SetRotation(axs, -ref_angle)
        elif 0 < ref_angle < np.pi / 2:
            trf.SetRotation(axs, np.pi - ref_angle)
        elif -np.pi / 2 < ref_angle < 0:
            trf.SetRotation(axs, -ref_angle - np.pi)
        else:
            trf.SetRotation(axs, -ref_angle)
        #trf.SetTransformation(axs3.Rotated(axs, angle), axs3)
        loc_face = TopLoc_Location(trf)
        new_face = face.Moved(loc_face)
        self.display.DisplayShape(new_face, transparency=0.5)
        self.display.DisplayShape(rim_angle)
        self.display.DisplayShape(rim_p0)
        self.display.DisplayShape(rim_p2)
        return new_face
Ejemplo n.º 6
0
def makeEdgesFacesIntersectPoints(edgesShape, facesShape):
    def findIntersectPoints(curve, surface):
        ps = []
        tool = GeomAPI_IntCS(curve, surface)
        pCount = tool.NbPoints()
        for i in range(1, pCount + 1):
            ps += [tool.Point(i)]
        return ps

    intersectPoints = []
    aEdges = getShapeItems(edgesShape, TopAbs_EDGE)
    aFaces = getShapeItems(facesShape, TopAbs_FACE)
    for aEdge in aEdges:
        for aFace in aFaces:
            # noinspection PyTypeChecker
            edgeCurves = BRep_Tool.Curve(aEdge)
            edgeTrimmedCurve = Geom_TrimmedCurve(edgeCurves[0], edgeCurves[1], edgeCurves[2])
            # noinspection PyTypeChecker
            faceSurface = BRep_Tool.Surface(aFace)
            foundIntersectPoints = findIntersectPoints(edgeTrimmedCurve, faceSurface)
            intersectPoints += foundIntersectPoints
    return intersectPoints
Ejemplo n.º 7
0
    obj.display.DisplayShape(rim_v, color="BLUE")
    print(api.GaussianCurvature())
    print(api.MinCurvature(), api.MeanCurvature(), api.MaxCurvature())
    print(dir_to_vec(api.Normal()))
    du, dv = gp_Dir(), gp_Dir()
    api.TangentU(du)
    api.TangentV(dv)
    print(dir_to_vec(du))
    print(dir_to_vec(dv))
    dx, dy = gp_Dir(), gp_Dir()
    api.CurvatureDirections(dx, dy)
    print(dir_to_vec(dx))
    print(dir_to_vec(dy))
    axs_x = gp_Ax3(pnt, dx, api.Normal())
    axs_x = obj.prop_axs(axs_x, -np.abs(1 / api.MaxCurvature()), xyz="x")
    rim_x = Geom_TrimmedCurve(Geom_Circle(axs_x.Ax2(), np.abs(1 / api.MaxCurvature())),
                              -np.pi / 2 / 10, np.pi / 2 / 10)
    # obj.display.DisplayShape(rim_x)
    axs_y = gp_Ax3(pnt, dy, api.Normal())
    axs_y = obj.prop_axs(axs_y, -np.abs(1 / api.MinCurvature()), xyz="x")
    rim_y = Geom_TrimmedCurve(Geom_Circle(axs_y.Ax2(), np.abs(1 / api.MinCurvature())),
                              -np.pi / 2 / 10, np.pi / 2 / 10)
    # obj.display.DisplayShape(rim_y)

    obj.show_axs_pln(ax0, scale=100, name="axis-0")
    obj.show_axs_pln(ax1, scale=100, name="axis-1")
    obj.show_axs_pln(ax2, scale=25, name="axis-2")
    obj.display.DisplayShape(surf, color="BLUE", transparency=0.9)
    obj.show_axs_pln(scale=100)
    obj.show()