def MakePentagonFace(self, Diameter: float, Radius: float) -> TopoDS_Face:
        tubeRadius = Diameter / 2.0
        upX     = tubeRadius * math.cos( 18 * math.pi / 180. )
        upY     = tubeRadius * math.sin( 18 * math.pi / 180. )
        downX   = tubeRadius * math.sin( 36 * math.pi / 180. )
        downY   = tubeRadius * math.cos( 36 * math.pi / 180. )

        p1 = gp_Pnt( 0.,        tubeRadius, 0. )
        p2 = gp_Pnt( upX,       upY,        0. )
        p3 = gp_Pnt( downX,     -downY,     0. )
        p4 = gp_Pnt( -downX,    -downY,     0. )
        p5 = gp_Pnt( -upX,      upY,        0. )

        ed1 = make_edge( p1, p2 )
        ed2 = make_edge( p2, p3 )
        ed3 = make_edge( p3, p4 )
        ed4 = make_edge( p4, p5 )
        ed5 = make_edge( p5, p1 )

        pln = gp_Pln( gp_Pnt( 0., 0., 0. ), gp_Dir( 0., 0., 1. ) )

        cur1 = self.__MakeFillet( ed1, ed2, pln, Radius )
        cur2 = self.__MakeFillet( ed2, ed3, pln, Radius )
        cur3 = self.__MakeFillet( ed3, ed4, pln, Radius )
        cur4 = self.__MakeFillet( ed4, ed5, pln, Radius )
        cur5 = self.__MakeFillet( ed5, ed1, pln, Radius )

        edgeList = [ed1, cur1, ed2, cur2, ed3, cur3, ed4, cur4, ed5, cur5]

        wire = make_wire( edgeList )

        return make_face( wire )
    def MakeTriangleFace(self, Diameter: float, Radius: float) -> TopoDS_Face:
        tubeRadius  = Diameter / 2.0
        degree      = 30 * math.pi / 180.
        sindis      = tubeRadius * math.sin( degree )
        cosdis      = tubeRadius * math.cos( degree )

        p1 = gp_Pnt( 0.,        tubeRadius, 0. )
        p2 = gp_Pnt( -cosdis,   -sindis,    0. )
        p3 = gp_Pnt( cosdis,    -sindis,    0. )

        ed1 = make_edge( p1, p2 )
        ed2 = make_edge( p2, p3 )
        ed3 = make_edge( p3, p1 )

        pln = gp_Pln( gp_Pnt( 0., 0., 0. ), gp_Dir( 0., 0., 1. ) )

        cur1 = self.__MakeFillet( ed1, ed2, pln, Radius )
        cur2 = self.__MakeFillet( ed2, ed3, pln, Radius )
        cur3 = self.__MakeFillet( ed3, ed1, pln, Radius )

        edgeList = [ed1, cur1, ed2, cur2, ed3, cur3]

        wire = make_wire( edgeList )

        return make_face( wire )
Exemple #3
0
def rotate(event=None):
    display.EraseAll()
    origin = gp_Vec(0, 0, 0)
    origin_pt = as_pnt(origin)

    vX = gp_Vec(12, 0, 0)
    vY = gp_Vec(0, 12, 0)
    v45 = (gp_Vec(1, 1, 1).Normalized() * 12)
    q1 = gp_Quaternion(vX, vY)

    p1 = as_pnt(origin + vX)
    p2 = as_pnt(origin + vY)
    p3 = as_pnt(origin + (q1 * vY))
    p4 = as_pnt(origin + (q1 * v45))

    # RED
    e1 = make_edge(origin_pt, p1)
    e2 = make_edge(origin_pt, p2)
    e3 = make_edge(origin_pt, as_pnt(v45))
    # GREEN -> transformed
    e4 = make_edge(origin_pt, p3)
    e5 = make_edge(origin_pt, p4)

    display.DisplayShape([e1, e2, e3])
    display.DisplayColoredShape([e4, e5], 'GREEN')
    display.DisplayMessage(p1, 'e1')
    display.DisplayMessage(p2, 'e2')
    display.DisplayMessage(as_pnt(v45), 'e3')
    display.DisplayMessage(p3, 'q1*vY')
    display.DisplayMessage(p4, 'q1*v45')
    display.DisplayVector((q1 * vY).Normalized(), as_pnt(origin + q1 * vY / 2.))
    display.DisplayVector((q1 * v45).Normalized(), as_pnt(origin + q1 * v45 / 2.))
    display.FitAll()
    def MakeSquareFace(self, Width: float, High: float, Radius: float) -> TopoDS_Face:
        xDis = Width / 2.0
        yDis = High / 2.0

        p1 = gp_Pnt( xDis,  yDis,   0. )
        p2 = gp_Pnt( xDis,  -yDis,  0. )
        p3 = gp_Pnt( -xDis, -yDis,  0. )
        p4 = gp_Pnt( -xDis, yDis,   0. )

        ed1 = make_edge( p1, p2 )
        ed2 = make_edge( p2, p3 )
        ed3 = make_edge( p3, p4 )
        ed4 = make_edge( p4, p1 )

        pln = gp_Pln( gp_Pnt( 0., 0., 0. ), gp_Dir( 0., 0., 1. ) )

        cur1 = self.__MakeFillet( ed1, ed2, pln, Radius )
        cur2 = self.__MakeFillet( ed2, ed3, pln, Radius )
        cur3 = self.__MakeFillet( ed3, ed4, pln, Radius )
        cur4 = self.__MakeFillet( ed4, ed1, pln, Radius )

        edgeList = [ed1, cur1, ed2, cur2, ed3, cur3, ed4, cur4]

        wire = make_wire( edgeList )

        return make_face( wire )
Exemple #5
0
def make_face_to_contour_from():
    v1 = make_vertex(gp_Pnt(0, 0, 0))
    v2 = make_vertex(gp_Pnt(10, 0, 0))
    v3 = make_vertex(gp_Pnt(7, 10, 0))
    v4 = make_vertex(gp_Pnt(10, 20, 0))
    v5 = make_vertex(gp_Pnt(0, 20, 0))
    v6 = make_vertex(gp_Pnt(3, 10, 0))
    e1 = make_edge(v1, v2)
    e2 = make_edge(v2, v3)
    e3 = make_edge(v3, v4)
    e4 = make_edge(v4, v5)
    e5 = make_edge(v5, v6)
    e6 = make_edge(v6, v1)
    v7 = make_vertex(gp_Pnt(2, 2, 0))
    v8 = make_vertex(gp_Pnt(8, 2, 0))
    v9 = make_vertex(gp_Pnt(7, 3, 0))
    v10 = make_vertex(gp_Pnt(3, 3, 0))
    e7 = make_edge(v7, v8)
    e8 = make_edge(v8, v9)
    e9 = make_edge(v9, v10)
    e10 = make_edge(v10, v7)
    w1 = make_wire([e1, e2, e3, e4, e5, e6])
    f = make_face(w1)
    w2 = make_wire(e7, e8, e9, e10)
    f2 = make_face(w2)
    f3 = boolean_cut(f, f2)
    return f3
Exemple #6
0
def axs_pln(axs):
    pnt = axs.Location()
    vx = dir_to_vec(axs.XDirection()).Scaled(100)
    vy = dir_to_vec(axs.YDirection()).Scaled(200)
    vz = dir_to_vec(axs.Direction()).Scaled(300)
    lx = make_edge(pnt, gp_Pnt((gp_Vec(pnt.XYZ()) + vx).XYZ()))
    ly = make_edge(pnt, gp_Pnt((gp_Vec(pnt.XYZ()) + vy).XYZ()))
    lz = make_edge(pnt, gp_Pnt((gp_Vec(pnt.XYZ()) + vz).XYZ()))
    return lx, ly, lz
    def make_shape(self):
        # 1 - retrieve the data from the UIUC airfoil data page
        foil_dat_url = 'http://m-selig.ae.illinois.edu/ads/coord_seligFmt/%s.dat' % self.profile
        # explicitly tell to not use ssl verification
        ssl._create_default_https_context = ssl._create_unverified_context
        print("Connecting to m-selig, retrieving foil data")
        f = urllib2.urlopen(foil_dat_url)
        print("Building foil geometry")
        plan = gp_Pln(gp_Pnt(0., 0., 0.), gp_Dir(0., 0.,
                                                 1.))  # Z=0 plan / XY plan
        section_pts_2d = []

        for line in f.readlines()[1:]:  # The first line contains info only
            # 2 - do some cleanup on the data (mostly dealing with spaces)
            data = line.split()
            # 3 - create an array of points
            if len(data) == 2:  # two coordinates for each point
                section_pts_2d.append(
                    gp_Pnt2d(
                        float(data[0]) * self.chord,
                        float(data[1]) * self.chord))

        # 4 - use the array to create a spline describing the airfoil section
        spline_2d = Geom2dAPI_PointsToBSpline(
            point2d_list_to_TColgp_Array1OfPnt2d(section_pts_2d),
            len(section_pts_2d) - 1,  # order min
            len(section_pts_2d))  # order max
        spline = geomapi.To3d(spline_2d.Curve(), plan)

        # 5 - figure out if the trailing edge has a thickness or not,
        # and create a Face
        try:
            #first and last point of spline -> trailing edge
            trailing_edge = make_edge(
                gp_Pnt(section_pts_2d[0].X(), section_pts_2d[0].Y(), 0.0),
                gp_Pnt(section_pts_2d[-1].X(), section_pts_2d[-1].Y(), 0.0))
            face = BRepBuilderAPI_MakeFace(
                make_wire([make_edge(spline), trailing_edge]))
        except AssertionError:
            # the trailing edge segment could not be created, probably because
            # the points are too close
            # No need to build a trailing edge
            face = BRepBuilderAPI_MakeFace(make_wire(make_edge(spline)))

        # 6 - extrude the Face to create a Solid
        return BRepPrimAPI_MakePrism(
            face.Face(), gp_Vec(gp_Pnt(0., 0., 0.),
                                gp_Pnt(0., 0., self.span))).Shape()
    def _create_edges_from_path(cls, path):
        assert isinstance(path, Path)
        edges = []
        create_gp_pnt = cls._get_create_gp_pnt_func()
        for geom in path:
            if isinstance(geom, Line):
                start = geom.start
                end = geom.end
                p1 = create_gp_pnt((start.real, start.imag))
                p2 = create_gp_pnt((end.real, end.imag))
                edges.append(make_edge(p1, p2))
            elif isinstance(geom, CubicBezier):
                edges.append(
                    cls._create_edge_from_bezier_pts(geom.start, geom.end,
                                                     geom.control1,
                                                     geom.control2))
            elif isinstance(geom, QuadraticBezier):
                edges.append(
                    cls._create_edge_from_bezier_pts(geom.start, geom.end,
                                                     geom.control))
            elif isinstance(geom, Arc):
                raise NotImplementedError()
                # https://github.com/tpaviot/pythonocc-core/issues/773

                # Have to do mirroring here rather than as a part of the path scaling because the svgpathtools.Arc
                # class does not support scaling with different x and y scaling factors.
                # mirror over the x-axis to make the face right-side up.
                # Loading from the document makes everthing upside-down.
                # mirror = gp_Trsf()
                # mirror.SetMirror(gp_OX())
                # mirrored_face = BRepBuilderAPI_Transform(faceMaker.Shape(), mirror, True).Shape()
                # return mirrored_face

                # from OCC.Core.gp import gp_Elips, gp_Ax2, gp_Pnt, gp_Dir
                # from OCC.Core.GC import GC_MakeArcOfEllipse
                # from OCC.Core.BRepBuilderAPI import BRepBuilderAPI_MakeEdge
                # # from svgpathtools import Arc
                # from constants import DIR_Y, DIR_X, DIR_Z
                # import math
                # arc=line
                #
                # major_radius = max(math.hypot(arc.radius.real, arc.radius.imag),
                #                    math.hypot(arc.start.real - arc.end.imag, arc.start.imag - arc.end.imag))
                # minor_radius = min(math.hypot(arc.radius.real, arc.radius.imag),
                #                    math.hypot(arc.start.real - arc.end.imag, arc.start.imag - arc.end.imag))
                # # https://old.opencascade.com/doc/occt-6.9.0/refman/html/classgp___elips.html#a9658323f6a5c4282e3b635e4642bfc56
                # assert major_radius >= minor_radius  # enforced by OCC
                # ellipse_gp = gp_Elips(gp_Ax2(create_gp_pnt((arc.center.real, arc.center.imag)), DIR_Y), major_radius, minor_radius)
                # # ellipse = BRepBuilderAPI_MakeEdge(ellipse_gp).Edge()
                # # ellipse_geom = GC_MakeArcOfEllipse(ellipse_gp, 0.0, math.pi / 2, True).Value()
                # # ellipse_geom = GC_MakeArcOfEllipse(ellipse_gp, gp_Pnt(start.real, 0, start.imag), gp_Pnt(end.real, 0, end.imag), True).Value() # between points
                # ellipse_geom = GC_MakeArcOfEllipse(ellipse_gp, 0, math.pi, True).Value()
                # edge = BRepBuilderAPI_MakeEdge(ellipse_geom).Edge()
                # # display.DisplayShape(edge, update=True, color="WHITE")
                #
                # wireMaker.Add(edge)
            else:
                raise RuntimeError("Invalid geom type: {}".format(type(geom)))
        return edges
Exemple #9
0
    def test_get_perp_faces_XZ_plane(self):
        perp_faces_HE = get_perp_faces(get_faces(self.compound_HE), gp_Vec(0, 1, 0))
        self.assertEqual(22, len(perp_faces_HE))

        perp_faces_GE = get_perp_faces(get_faces(self.compound_GE), gp_Vec(0, 1, 0))
        self.assertEqual(39, len(perp_faces_GE))

        perp_faces_VT = get_perp_faces(get_faces(self.compound_VT), gp_Vec(0, 1, 0))
        self.assertEqual(11, len(perp_faces_VT))

        for f in perp_faces_VT:
            display.DisplayShape(f, transparency=0.7)

        display.DisplayShape(make_edge(LINE_X), update=True, color="RED")
        display.DisplayShape(make_edge(LINE_Y), update=True, color="GREEN")
        display.DisplayShape(make_edge(LINE_Z), update=True, color="BLUE")
        start_display()
Exemple #10
0
    def test_get_nonperp_faces_YZ_plane(self):
        nonperp_faces_HE = get_nonperp_faces(get_faces(self.compound_HE), gp_Vec(1, 0, 0))
        self.assertEqual(6, len(nonperp_faces_HE))

        nonperp_faces_GE = get_nonperp_faces(get_faces(self.compound_GE), gp_Vec(1, 0, 0))
        self.assertEqual(23, len(nonperp_faces_GE))

        nonperp_faces_VT = get_nonperp_faces(get_faces(self.compound_VT), gp_Vec(1, 0, 0))
        self.assertEqual(4, len(nonperp_faces_VT))

        for f in nonperp_faces_GE:
            display.DisplayShape(f, transparency=0.7)

        display.DisplayShape(make_edge(LINE_X), update=True, color="RED")
        display.DisplayShape(make_edge(LINE_Y), update=True, color="GREEN")
        display.DisplayShape(make_edge(LINE_Z), update=True, color="BLUE")
        start_display()
def geom_plate():
    p1 = gp_Pnt(0, 0, 0)
    p2 = gp_Pnt(10, 0, 0)
    p3 = gp_Pnt(10, 0, 9)
    p4 = gp_Pnt(0, 1, 1)
    p5 = gp_Pnt(5, 5, 0)
    edge = [p1, p2, p3, p4]
    edge.append(edge[0])
    poly = [make_edge(edge[i], edge[i + 1]) for i in range(len(edge) - 1)]
    face = make_n_sided(poly)
    return face
    def MakeHexagonFace(self, Diameter: float, Radius: float) -> TopoDS_Face:
        tubeRadius  = Diameter / 2.0
        degree      = 60 * math.pi / 180.
        sindis      = tubeRadius * math.sin( degree )
        cosdis      = tubeRadius * math.cos( degree )

        p1 = gp_Pnt( cosdis,        sindis,     0. )
        p2 = gp_Pnt( tubeRadius,    0.,         0. )
        p3 = gp_Pnt( cosdis,        -sindis,    0. )
        p4 = gp_Pnt( -cosdis,       -sindis,    0. )
        p5 = gp_Pnt( -tubeRadius,   0.,         0. )
        p6 = gp_Pnt( -cosdis,       sindis,     0. )

        ed1 = make_edge( p1, p2 )
        ed2 = make_edge( p2, p3 )
        ed3 = make_edge( p3, p4 )
        ed4 = make_edge( p4, p5 )
        ed5 = make_edge( p5, p6 )
        ed6 = make_edge( p6, p1 )

        pln = gp_Pln( gp_Pnt( 0., 0., 0. ), gp_Dir( 0., 0., 1. ) )

        cur1 = self.__MakeFillet( ed1, ed2, pln, Radius )
        cur2 = self.__MakeFillet( ed2, ed3, pln, Radius )
        cur3 = self.__MakeFillet( ed3, ed4, pln, Radius )
        cur4 = self.__MakeFillet( ed4, ed5, pln, Radius )
        cur5 = self.__MakeFillet( ed5, ed6, pln, Radius )
        cur6 = self.__MakeFillet( ed6, ed1, pln, Radius )

        edgeList = [ed1, cur1, ed2, cur2, ed3, cur3, ed4, cur4, ed5, cur5, ed6, cur6]

        wire = make_wire( edgeList )

        return make_face( wire )
def compute_minimal_distance_between_circles():
    """ compute the minimal distance between 2 circles

    here the minimal distance overlaps the intersection of the circles
    the points are rendered to indicate the locations

    """
    # required for precise rendering of the circles
    display.Context.SetDeviationCoefficient(0.0001)
    L = gp_Pnt(4, 10, 0)
    M = gp_Pnt(10, 16, 0)

    Laxis = gp_Ax2()
    Maxis = gp_Ax2()
    Laxis.SetLocation(L)
    Maxis.SetLocation(M)

    r1 = 12.0
    r2 = 15.0
    Lcircle = gp_Circ(Laxis, r1)
    Mcircle = gp_Circ(Maxis, r2)

    l_circle, m_circle = make_edge(Lcircle), make_edge(Mcircle)
    display.DisplayShape([l_circle, m_circle])

    # compute the minimal distance between 2 circles
    # the minimal distance here matches the intersection of the circles
    dss = BRepExtrema_DistShapeShape(l_circle, m_circle)

    print("intersection parameters on l_circle:",
          [dss.ParOnEdgeS1(i) for i in range(1,
                                             dss.NbSolution() + 1)])
    print("intersection parameters on m_circle:",
          [dss.ParOnEdgeS2(i) for i in range(1,
                                             dss.NbSolution() + 1)])

    for i in range(1, dss.NbSolution() + 1):
        pnt = dss.PointOnShape1(i)
        display.DisplayShape(make_vertex(pnt))
def compute_minimal_distance_between_cubes():
    """ compute the minimal distance between 2 cubes

    the line between the 2 points is rendered in cyan

    """
    b1 = BRepPrimAPI_MakeBox(gp_Pnt(100, 0, 0), 10., 10., 10.).Shape()
    b2 = BRepPrimAPI_MakeBox(gp_Pnt(45, 45, 45), 10., 10., 10.).Shape()
    display.DisplayShape([b1, b2])

    dss = BRepExtrema_DistShapeShape()
    dss.LoadS1(b1)
    dss.LoadS2(b2)
    dss.Perform()

    assert dss.IsDone()

    edg = make_edge(dss.PointOnShape1(1), dss.PointOnShape2(1))
    display.DisplayColoredShape([edg], color="CYAN")
Exemple #15
0
    def gen_fill(self):
        # curv = GeomAPI_PointsToBSplineSurface(
        #    self.pnt_2d, 3, 8, GeomAbs_G2, 0.001).Surface()
        # surf = BRepBuilderAPI_MakeFace(curv, 1e-6).Face()
        # self.display.DisplayShape(surf)

        for idx_row in range(self.pnt_2d.LowerRow(), self.pnt_2d.UpperRow()):
            for idx_col in range(self.pnt_2d.LowerCol(),
                                 self.pnt_2d.UpperCol()):
                i00, i01 = idx_row, idx_row + 1
                i10, i11 = idx_col, idx_col + 1
                p1 = self.pnt_2d.Value(i00, i10)
                p2 = self.pnt_2d.Value(i01, i10)
                p3 = self.pnt_2d.Value(i01, i11)
                p4 = self.pnt_2d.Value(i00, i11)
                edge = [p1, p2, p3, p4]
                edge.append(edge[0])
                poly = [
                    make_edge(edge[i], edge[i + 1])
                    for i in range(len(edge) - 1)
                ]
                face = make_n_sided(poly)
                self.display.DisplayShape(face)
Exemple #16
0
def interpolate(event=None):
    display.EraseAll()

    origin = gp_Vec()
    vX = gp_Vec(12, 0, 0)
    vY = gp_Vec(0, 12, 0)
    v45 = (gp_Vec(1, 1, 1).Normalized() * 12)

    q = gp_Quaternion()
    interp = gp_QuaternionSLerp(gp_Quaternion(vX, vX), gp_Quaternion(vX, vY))

    for i in frange(0, 1.0, 0.01):
        interp.Interpolate(i, q)
        # displace the white edges a little from the origin so not to obstruct the other edges
        v = gp_Vec(0, -24*i, 0)
        q_v_ = q * v45
        p = gp_Pnt((q_v_ + v).XYZ())
        v__as_pnt = gp_Pnt((origin + v).XYZ())
        e = make_edge(v__as_pnt, p)
        display.DisplayColoredShape(e, 'WHITE')
        msg = 'v45->q1*v45 @{0}'.format(i / 10.)
        display.DisplayMessage(p, msg)
    display.FitAll()
    def MakeCircleFace(self, Radius: float) -> TopoDS_Face:
        circle  = Geom_Circle( gp_XOY(), Radius )
        ed      = make_edge( circle )
        wire    = make_wire( ed )

        return make_face( wire )
    def MakeEllipsFace(self, Major: float, Minor: float) -> TopoDS_Face:
        elip    = gp_Elips( gp_XOY(), Major, Minor )
        ed      = make_edge( elip )
        wire    = make_wire( ed )

        return make_face( wire )