Example #1
0
def points_from_intersection():
    '''
    @param display:
    '''
    plane = gp_Pln(gp_Ax3(gp_XOY()))
    minor_radius, major_radius = 5., 8.
    ellips = gp_Elips(gp_YOZ(), major_radius, minor_radius)
    intersection = IntAna_IntConicQuad(ellips, plane, precision_Angular(),
                                       precision_Confusion())
    a_plane = GC_MakePlane(plane).Value()
    a_surface = Geom_RectangularTrimmedSurface(a_plane, -8., 8., -12., 12.,
                                               True, True)
    display.DisplayShape(a_surface, update=True)

    anEllips = GC_MakeEllipse(ellips).Value()
    display.DisplayShape(anEllips)

    if intersection.IsDone():
        nb_results = intersection.NbPoints()
        if nb_results > 0:
            for i in range(1, nb_results + 1):
                P = intersection.Point(i)
                pstring = "P%i" % i
                display.DisplayShape(P)
                display.DisplayMessage(P, pstring)
Example #2
0
def clone_tooth(base_shape):
    clone = gp_Trsf()
    grouped_shape = base_shape

    # Find a divisor, between 1 and 8, for the number_of teeth
    multiplier = 1
    max_multiplier = 1
    for i in range(0, 8):
        if num_teeth % multiplier == 0:
            max_multiplier = i + 1

    multiplier = max_multiplier
    for i in range(1, multiplier):
        clone.SetRotation(gp_OZ(), -i * tooth_angle)
        rotated_shape = BRepBuilderAPI_Transform(base_shape, clone,
                                                 True).Shape()
        grouped_shape = BRepAlgoAPI_Fuse(grouped_shape, rotated_shape).Shape()

    # Rotate the basic tooth and fuse together
    aggregated_shape = grouped_shape
    for i in range(1, int(num_teeth / multiplier)):
        clone.SetRotation(gp_OZ(), -i * multiplier * tooth_angle)
        rotated_shape = BRepBuilderAPI_Transform(grouped_shape, clone,
                                                 True).Shape()
        aggregated_shape = BRepAlgoAPI_Fuse(aggregated_shape,
                                            rotated_shape).Shape()

    cylinder = BRepPrimAPI_MakeCylinder(gp_XOY(), top_radius - roller_diameter,
                                        thickness)
    aggregated_shape = BRepAlgoAPI_Fuse(aggregated_shape,
                                        cylinder.Shape()).Shape()

    return aggregated_shape
Example #3
0
def project_point_on_curve():
    '''
    '''
    point_to_project = gp_Pnt(1., 2., 3.)
    radius = 5.

    # create a circle, centered at origin with a given radius
    circle = Geom_Circle(gp_XOY(), radius)
    display.DisplayShape(circle)
    display.DisplayShape(point_to_project, update=True)
    display.DisplayMessage(point_to_project, "P")

    # project the point P on the circle
    projection = GeomAPI_ProjectPointOnCurve(point_to_project,
                                             circle.GetHandle())
    # get the results of the projection
    # the point
    projected_point = projection.NearestPoint()
    # the number of possible results
    nb_results = projection.NbPoints()
    print("NbResults : %i" % nb_results)

    pstring = "N : at Distance : %f" % projection.LowerDistance()
    display.DisplayMessage(projected_point, pstring)

    # thre maybe many different possible solutions
    if nb_results > 0:
        for i in range(1, nb_results+1):
            Q = projection.Point(i)
            distance = projection.Distance(i)
            pstring = "Q%i: at Distance :%f" % (i, distance)
            display.DisplayShape(Q)
            display.DisplayMessage(Q, pstring)
def points_from_intersection(event=None):
    '''
    @param display:
    '''
    plane = gp_Pln(gp_Ax3(gp_XOY()))
    minor_radius, major_radius = 5., 8.
    ellips = gp_Elips(gp_YOZ(), major_radius, minor_radius)
    intersection = IntAna_IntConicQuad(ellips,
                                       plane,
                                       precision_Angular(),
                                       precision_Confusion())
    a_plane = GC_MakePlane(plane).Value()
    a_surface = Geom_RectangularTrimmedSurface(a_plane, - 8., 8., - 12., 12.,
                                               True, True)
    display.DisplayShape(a_surface, update=True)

    anEllips = GC_MakeEllipse(ellips).Value()
    display.DisplayShape(anEllips)

    if intersection.IsDone():
        nb_results = intersection.NbPoints()
        if nb_results > 0:
            for i in range(1, nb_results + 1):
                P = intersection.Point(i)
                pstring = "P%i" % i
                display.DisplayShape(P)
                display.DisplayMessage(P, pstring)
def test_project_curve_to_plane():
    # Projects a line of length 1 from above the XOY plane, and tests points
    # on the resulting line
    from OCC.Geom import Geom_Plane, Geom_TrimmedCurve
    from OCC.GC import GC_MakeSegment
    from OCC.gp import gp_Ax3, gp_XOY, gp_Pnt, gp_Dir
    XOY = Geom_Plane(gp_Ax3(gp_XOY()))
    curve = GC_MakeSegment(gp_Pnt(0, 0, 5),
                           gp_Pnt(1, 0, 5)).Value()
    direction = gp_Dir(0, 0, 1)

    Hproj_curve = act.project_curve_to_plane(curve, XOY.GetHandle(),
                                            direction)

    proj_curve = Hproj_curve.GetObject()

    # The start and end points of the curve
    p1 = proj_curve.Value(0)
    p2 = proj_curve.Value(1)

    p1_array = np.array([p1.X(), p1.Y(), p1.Z()])
    p2_array = np.array([p2.X(), p2.Y(), p2.Z()])

    # The expected start and end points
    start = np.array([0, 0, 0])
    end = np.array([1, 0, 0])

    # Assert that neither points have a Y or Z component, and that
    assert((np.all(p1_array == start) and np.all(p2_array == end)) or
           (np.all(p1_array == end) and np.all(p2_array == start)))
def project_point_on_curve():
    """
    """
    point_to_project = gp_Pnt(1.0, 2.0, 3.0)
    radius = 5.0

    # create a circle, centered at origin with a given radius
    circle = Geom_Circle(gp_XOY(), radius)
    display.DisplayShape(circle)
    display.DisplayShape(point_to_project, update=True)
    display.DisplayMessage(point_to_project, "P")

    # project the point P on the circle
    projection = GeomAPI_ProjectPointOnCurve(point_to_project, circle.GetHandle())
    # get the results of the projection
    # the point
    projected_point = projection.NearestPoint()
    # the number of possible results
    nb_results = projection.NbPoints()
    print("NbResults : %i" % nb_results)

    pstring = "N : at Distance : %f" % projection.LowerDistance()
    display.DisplayMessage(projected_point, pstring)

    # thre maybe many different possible solutions
    if nb_results > 0:
        for i in range(1, nb_results + 1):
            Q = projection.Point(i)
            distance = projection.Distance(i)
            pstring = "Q%i: at Distance :%f" % (i, distance)
            display.DisplayShape(Q)
            display.DisplayMessage(Q, pstring)
Example #7
0
def draft_angle(event=None):
    S = BRepPrimAPI_MakeBox(200., 300., 150.).Shape()
    adraft = BRepOffsetAPI_DraftAngle(S)
    topExp = TopExp_Explorer()
    topExp.Init(S, TopAbs_FACE)
    while topExp.More():
        face = topods_Face(topExp.Current())
        surf = Handle_Geom_Plane_DownCast(BRep_Tool_Surface(face)).GetObject()
        dirf = surf.Pln().Axis().Direction()
        ddd = gp_Dir(0, 0, 1)
        if dirf.IsNormal(ddd, precision_Angular()):
            adraft.Add(face, ddd, math.radians(15), gp_Pln(gp_Ax3(gp_XOY())))
        topExp.Next()
    adraft.Build()
    display.DisplayShape(adraft.Shape(), update=True)
def draft_angle(event=None):
    S = BRepPrimAPI_MakeBox(200., 300., 150.).Shape()
    adraft = BRepOffsetAPI_DraftAngle(S)
    topExp = TopExp_Explorer()
    topExp.Init(S, TopAbs_FACE)
    while topExp.More():
        face = topods_Face(topExp.Current())
        surf = Handle_Geom_Plane_DownCast(BRep_Tool_Surface(face)).GetObject()
        dirf = surf.Pln().Axis().Direction()
        ddd = gp_Dir(0, 0, 1)
        if dirf.IsNormal(ddd, precision_Angular()):
            adraft.Add(face, ddd, math.radians(15), gp_Pln(gp_Ax3(gp_XOY())))
        topExp.Next()
    adraft.Build()
    display.DisplayShape(adraft.Shape(), update=True)
Example #9
0
def round_tooth(wedge):
    round_x = 2.6
    round_z = 0.06 * pitch
    round_radius = pitch

    # Determine where the circle used for rounding has to start and stop
    p2d_1 = gp_Pnt2d(top_radius - round_x, 0)
    p2d_2 = gp_Pnt2d(top_radius, round_z)

    # Construct the rounding circle
    round_circle = GccAna_Circ2d2TanRad(p2d_1, p2d_2, round_radius, 0.01)
    if (round_circle.NbSolutions() != 2):
        exit(-2)

    round_circle_2d_1 = round_circle.ThisSolution(1)
    round_circle_2d_2 = round_circle.ThisSolution(2)

    if (round_circle_2d_1.Position().Location().Coord()[1] >= 0):
        round_circle_2d = round_circle_2d_1
    else:
        round_circle_2d = round_circle_2d_2

    # Remove the arc used for rounding
    trimmed_circle = GCE2d_MakeArcOfCircle(round_circle_2d, p2d_1,
                                           p2d_2).Value()

    # Calculate extra points used to construct lines
    p1 = gp_Pnt(p2d_1.X(), 0, p2d_1.Y())
    p2 = gp_Pnt(p2d_2.X(), 0, p2d_2.Y())
    p3 = gp_Pnt(p2d_2.X() + 1, 0, p2d_2.Y())
    p4 = gp_Pnt(p2d_2.X() + 1, 0, p2d_1.Y() - 1)
    p5 = gp_Pnt(p2d_1.X(), 0, p2d_1.Y() - 1)

    # Convert the arc and four extra lines into 3D edges
    plane = gp_Pln(gp_Ax3(gp_Origin(), gp_DY().Reversed(), gp_DX()))
    arc1 = BRepBuilderAPI_MakeEdge(geomapi_To3d(trimmed_circle, plane)).Edge()
    lin1 = BRepBuilderAPI_MakeEdge(p2, p3).Edge()
    lin2 = BRepBuilderAPI_MakeEdge(p3, p4).Edge()
    lin3 = BRepBuilderAPI_MakeEdge(p4, p5).Edge()
    lin4 = BRepBuilderAPI_MakeEdge(p5, p1).Edge()

    # Make a wire composed of the edges
    round_wire = BRepBuilderAPI_MakeWire(arc1)
    round_wire.Add(lin1)
    round_wire.Add(lin2)
    round_wire.Add(lin3)
    round_wire.Add(lin4)

    # Turn the wire into a face
    round_face = BRepBuilderAPI_MakeFace(round_wire.Wire()).Shape()

    # Revolve the face around the Z axis over the tooth angle
    rounding_cut_1 = BRepPrimAPI_MakeRevol(round_face, gp_OZ(),
                                           tooth_angle).Shape()

    # Construct a mirrored copy of the first cutting shape
    mirror = gp_Trsf()
    mirror.SetMirror(gp_XOY())
    mirrored_cut_1 = BRepBuilderAPI_Transform(rounding_cut_1, mirror,
                                              True).Shape()

    # and translate it so that it ends up on the other side of the wedge
    translate = gp_Trsf()
    translate.SetTranslation(gp_Vec(0, 0, thickness))
    rounding_cut_2 = BRepBuilderAPI_Transform(mirrored_cut_1, translate,
                                              False).Shape()

    # Cut the wedge using the first and second cutting shape
    cut_1 = BRepAlgoAPI_Cut(wedge, rounding_cut_1).Shape()
    cut_2 = BRepAlgoAPI_Cut(cut_1, rounding_cut_2).Shape()

    return cut_2
 def CreateConstructionGeometry(self):
     """
     Creates the plane and vector used for projecting wetted area
     """
     self.XoY_Plane = Geom_Plane(gp_Ax3(gp_XOY()))
     self.ProjVectorZ = gp_Dir(0, 0, 1)
Example #11
0
 def CreateConstructionGeometry(self):
     """
     Creates the plane and vector used for projecting wetted area
     """
     self.XoY_Plane = Geom_Plane(gp_Ax3(gp_XOY()))
     self.ProjVectorZ = gp_Dir(0, 0, 1)