Exemple #1
0
def curves2d_from_offset(event=None):
    '''
    @param display:
    '''
    pnt2d_array = TColgp_Array1OfPnt2d(1, 5)
    pnt2d_array.SetValue(1, gp_Pnt2d(-4, 0))
    pnt2d_array.SetValue(2, gp_Pnt2d(-7, 2))
    pnt2d_array.SetValue(3, gp_Pnt2d(-6, 3))
    pnt2d_array.SetValue(4, gp_Pnt2d(-4, 3))
    pnt2d_array.SetValue(5, gp_Pnt2d(-3, 5))

    spline_1 = Geom2dAPI_PointsToBSpline(pnt2d_array).Curve()

    dist = 1
    offset_curve1 = Geom2d_OffsetCurve(spline_1, dist)
    result = offset_curve1.IsCN(2)
    print("Offset curve yellow is C2: %r" % result)
    dist2 = 1.5
    offset_curve2 = Geom2d_OffsetCurve(spline_1, dist2)
    result2 = offset_curve2.IsCN(2)
    print("Offset curve blue is C2: %r" % result2)

    display.DisplayShape(spline_1)
    display.DisplayShape(offset_curve1, color='YELLOW')
    display.DisplayShape(offset_curve2, color='BLUE', update=True)
def extrusion(event=None):
    # Make a box
    Box = BRepPrimAPI_MakeBox(400., 250., 300.)
    S = Box.Shape()

    # Choose the first Face of the box
    F = next(TopologyExplorer(S).faces())
    surf = BRep_Tool_Surface(F)

    #  Make a plane from this face
    Pl = Handle_Geom_Plane_DownCast(surf)
    Pln = Pl.GetObject()

    # Get the normal of this plane. This will be the direction of extrusion.
    D = Pln.Axis().Direction()

    # Inverse normal
    D.Reverse()

    # Create the 2D planar sketch
    MW = BRepBuilderAPI_MakeWire()
    p1 = gp_Pnt2d(200., -100.)
    p2 = gp_Pnt2d(100., -100.)
    aline = GCE2d_MakeLine(p1, p2).Value()
    Edge1 = BRepBuilderAPI_MakeEdge(aline, surf, 0., p1.Distance(p2))
    MW.Add(Edge1.Edge())
    p1 = p2
    p2 = gp_Pnt2d(100., -200.)
    aline = GCE2d_MakeLine(p1, p2).Value()
    Edge2 = BRepBuilderAPI_MakeEdge(aline, surf, 0., p1.Distance(p2))
    MW.Add(Edge2.Edge())
    p1 = p2
    p2 = gp_Pnt2d(200., -200.)
    aline = GCE2d_MakeLine(p1, p2).Value()
    Edge3 = BRepBuilderAPI_MakeEdge(aline, surf, 0., p1.Distance(p2))
    MW.Add(Edge3.Edge())
    p1 = p2
    p2 = gp_Pnt2d(200., -100.)
    aline = GCE2d_MakeLine(p1, p2).Value()
    Edge4 = BRepBuilderAPI_MakeEdge(aline, surf, 0., p1.Distance(p2))
    MW.Add(Edge4.Edge())

    #  Build Face from Wire. NB: a face is required to generate a solid.
    MKF = BRepBuilderAPI_MakeFace()
    MKF.Init(surf, False, 1e-6)
    MKF.Add(MW.Wire())
    FP = MKF.Face()
    breplib_BuildCurves3d(FP)

    MKP = BRepFeat_MakePrism(S, FP, F, D, False, True)
    MKP.Perform(200.)
    # TODO MKP completes, seeing a split operation but no extrusion
    assert MKP.IsDone()
    res1 = MKP.Shape()

    display.EraseAll()
    display.DisplayColoredShape(res1, 'BLUE')
    display.FitAll()
 def testAutoImportOfDependentModules(self):
     """ Test: automatic import of dependent modules """
     returned_object = GCE2d_MakeSegment(gp_Pnt2d(1, 1),
                                         gp_Pnt2d(3, 4)).Value()
     # for this unittest, don't use the issinstance() function,
     # since the OCC.Geom2d module
     # is *not* manually imported
     returned_object_type = '%s' % type(returned_object)
     self.assertEqual(returned_object_type, "<class 'OCC.Core.Geom2d.Handle_Geom2d_TrimmedCurve'>")
 def test_auto_import_of_dependent_modules(self) -> None:
     """ Test: automatic import of dependent modules """
     returned_object = GCE2d_MakeSegment(gp_Pnt2d(1, 1),
                                         gp_Pnt2d(3, 4)).Value()
     # for this unittest, don't use the issinstance() function,
     # since the OCC.Geom2d module
     # is *not* manually imported
     returned_object_type = '%s' % type(returned_object)
     self.assertEqual(returned_object_type, "<class 'OCC.Core.Geom2d.Geom2d_TrimmedCurve'>")
Exemple #5
0
def bisect_pnt(event=None):
    display.EraseAll()
    p1 = gp_Pnt2d(1, 0.5)
    p2 = gp_Pnt2d(0, 1e5)
    bi = GccAna_Pnt2dBisec(p1, p2)
    bisec = bi.ThisSolution()
    # enum GccInt_Lin, GccInt_Cir, GccInt_Ell, GccInt_Par, GccInt_Hpr, GccInt_Pnt
    p1_ = make_vertex(gp_Pnt(p1.X(), p1.Y(), 0))
    p2_ = make_vertex(gp_Pnt(p2.X(), p2.Y(), 0))
    display.DisplayShape([p1_, p2_])
    display.DisplayColoredShape(make_edge2d(bisec), 'BLUE')
    display.FitAll()
Exemple #6
0
def bisect_lineline(event=None):
    display.EraseAll()
    li1 = gp_Lin2d(gp_Pnt2d(), gp_Dir2d(1, 0))
    li2 = gp_Lin2d(gp_Pnt2d(), gp_Dir2d(0, 1))

    bi = GccAna_Lin2dBisec(li1, li2)
    bi_li1 = bi.ThisSolution(1)
    bi_li2 = bi.ThisSolution(2)

    for i in [li1, li2]:
        display.DisplayShape(make_edge2d(i))
    for i in [bi_li1, bi_li2]:
        display.DisplayColoredShape(make_edge2d(i), 'BLUE')
    display.FitAll()
Exemple #7
0
def faircurve(event=None):
    pt1 = gp_Pnt2d(0., 0.)
    pt2 = gp_Pnt2d(0., 120.)
    height = 100.
    pl = Geom_Plane(gp_Pln())
    for i in range(0, 40):
        # TODO: the parameter slope needs to be visualized
        slope = i/100.
        bc = batten_curve(pt1, pt2, height, slope,
                          math.radians(i), math.radians(-i))
        display.EraseAll()
        edge = BRepBuilderAPI_MakeEdge(bc, pl).Edge()
        display.DisplayShape(edge, update=True)
        time.sleep(0.21)
def uniformdeflection_on_BSplineLst(BSplineLst, deflection):
    """
    distributes Points and NormalVectors on Geom2d_BSplineLst such that the
    concentration is higher in regions of high curvature
    
    """
    PntLst = []
    VecLst = []
    for item in BSplineLst:
        
        if isinstance(item,Geom_BSplineCurve):
            print('ERROR: Argument must be a Geom2d_BSplineLst')
                       
        Adaptor = Geom2dAdaptor_Curve(item)
        discretization = GCPnts_UniformDeflection(Adaptor,deflection)
        NbPoints = discretization.NbPoints()
        for j in range(1, NbPoints+1):
                para = discretization.Parameter(j)
                Pnt2d = gp_Pnt2d()
                Vec2d = gp_Vec2d()
                item.D1(para, Pnt2d, Vec2d)
                PntLst.append(Pnt2d)
                VecLst.append(Vec2d.GetNormal())
                
    return (PntLst, VecLst)
Exemple #9
0
    def _calc_cubic_parabola_point(self, lpt, L, R, ccw):

        x = lpt
        y = math.pow(x, 3) / (6 * R * L)
        if not ccw:
            y = -y

        return gp_Pnt2d(x, y)
Exemple #10
0
 def cline_gen(self, cline):
     '''Generate a cline extending to the edge of the border.
     cline coords (a,b,c) are in (mm) values.'''
     self.clList.append(cline)
     # TopLft & BotRgt corners of the border
     trimbox = (-self.size, self.size, self.size, -self.size)
     endpts = cline_box_intrsctn(cline, trimbox)
     if len(endpts) == 2:
         ep1, ep2 = endpts
         aPnt1 = gp_Pnt2d(ep1[0], ep1[1])
         aPnt2 = gp_Pnt2d(ep2[0], ep2[1])
         aSegment = GCE2d_MakeSegment(
             aPnt1, aPnt2).Value()  #type: Handle_Geom2d_TrimmedCurve
         # convert 2d line segment to 3d line
         aLine = geomapi_To3d(aSegment,
                              self.gpPlane)  # type: Handle_Geom_Curve
         self.clineList.append(aLine)
Exemple #11
0
 def gen_data_spline_2d(self, dat, ratio=1.0):
     num = dat.shape[0]
     pts = TColgp_Array1OfPnt2d(1, num)
     for i, xyz in enumerate(dat):
         pnt = gp_Pnt2d(xyz[0], xyz[1])
         pts.SetValue(i+1, pnt)
     geo_spl = Geom2dAPI_PointsToBSpline(pts)
     return geo_spl
    def test_circles2d_from_curves(self):
        '''Test: circles2d from curves'''
        P1 = gp_Pnt2d(9, 6)
        P2 = gp_Pnt2d(10, 4)
        P3 = gp_Pnt2d(6, 7)
        C = gce_MakeCirc2d(P1, P2, P3).Value()

        QC = gccent_Outside(C)
        P4 = gp_Pnt2d(-2, 7)
        P5 = gp_Pnt2d(12, -3)
        L = GccAna_Lin2d2Tan(P4, P5, precision_Confusion()).ThisSolution(1)

        QL = gccent_Unqualified(L)
        radius = 2.
        TR = GccAna_Circ2d2TanRad(QC, QL, radius, precision_Confusion())

        if TR.IsDone():
            NbSol = TR.NbSolutions()
            for k in range(1, NbSol+1):
                circ = TR.ThisSolution(k)
                # find the solution circle
                pnt1 = gp_Pnt2d()
                parsol, pararg = TR.Tangency1(k, pnt1)
                self.assertGreater(parsol, 0.)
                self.assertGreater(pararg, 0.)
                # find the first tangent point
                pnt2 = gp_Pnt2d()
                parsol, pararg = TR.Tangency2(k, pnt2)
                self.assertGreater(parsol, 0.)
                self.assertGreater(pararg, 0.)
                # find the second tangent point

        aLine = GCE2d_MakeSegment(L, -2, 20).Value()
        self.assertIsInstance(aLine, Geom2d_TrimmedCurve)
        if TR.IsDone():
            NbSol = TR.NbSolutions()
            for k in range(1, NbSol+1):
                circ = TR.ThisSolution(k)
                aCircle = Geom2d_Circle(circ)
                self.assertIsInstance(aCircle, Geom2d_Circle)
                # find the solution circle (index, outvalue, outvalue, gp_Pnt2d)
                pnt3 = gp_Pnt2d()
                parsol, pararg = TR.Tangency1(k, pnt3)
                self.assertGreater(parsol, 0.)
                self.assertGreater(pararg, 0.)
                # find the first tangent point
                pnt4 = gp_Pnt2d()
                parsol, pararg = TR.Tangency2(k, pnt4)
                self.assertGreater(parsol, 0.)
                self.assertGreater(pararg, 0.)
Exemple #13
0
    def test_circles2d_from_curves(self):
        '''Test: circles2d from curves'''
        P1 = gp_Pnt2d(9, 6)
        P2 = gp_Pnt2d(10, 4)
        P3 = gp_Pnt2d(6, 7)
        C = gce_MakeCirc2d(P1, P2, P3).Value()

        QC = gccent_Outside(C)
        P4 = gp_Pnt2d(-2, 7)
        P5 = gp_Pnt2d(12, -3)
        L = GccAna_Lin2d2Tan(P4, P5, precision_Confusion()).ThisSolution(1)

        QL = gccent_Unqualified(L)
        radius = 2.
        TR = GccAna_Circ2d2TanRad(QC, QL, radius, precision_Confusion())

        if TR.IsDone():
            NbSol = TR.NbSolutions()
            for k in range(1, NbSol + 1):
                circ = TR.ThisSolution(k)
                # find the solution circle
                pnt1 = gp_Pnt2d()
                parsol, pararg = TR.Tangency1(k, pnt1)
                self.assertGreater(parsol, 0.)
                self.assertGreater(pararg, 0.)
                # find the first tangent point
                pnt2 = gp_Pnt2d()
                parsol, pararg = TR.Tangency2(k, pnt2)
                self.assertGreater(parsol, 0.)
                self.assertGreater(pararg, 0.)
                # find the second tangent point

        aLine = GCE2d_MakeSegment(L, -2, 20).Value()
        self.assertIsInstance(aLine, Geom2d_TrimmedCurve)
        if TR.IsDone():
            NbSol = TR.NbSolutions()
            for k in range(1, NbSol + 1):
                circ = TR.ThisSolution(k)
                aCircle = Geom2d_Circle(circ)
                self.assertIsInstance(aCircle, Geom2d_Circle)
                # find the solution circle (index, outvalue, outvalue, gp_Pnt2d)
                pnt3 = gp_Pnt2d()
                parsol, pararg = TR.Tangency1(k, pnt3)
                self.assertGreater(parsol, 0.)
                self.assertGreater(pararg, 0.)
                # find the first tangent point
                pnt4 = gp_Pnt2d()
                parsol, pararg = TR.Tangency2(k, pnt4)
                self.assertGreater(parsol, 0.)
                self.assertGreater(pararg, 0.)
Exemple #14
0
def to_gp_pnt2d(p):
    """
    Convert the point_like entity to a gp_Pnt2d.
    """
    if isinstance(p, gp_Pnt2d):
        return p
    if is_array_like(p) and len(p) == 2:
        return gp_Pnt2d(*p)
    return None
Exemple #15
0
 def makeSqProfile(self, size):
     # points and segments need to be in CW sequence to get W pointing along Z
     p1 = gp_Pnt2d(-size, size)
     p2 = gp_Pnt2d(size, size)
     p3 = gp_Pnt2d(size, -size)
     p4 = gp_Pnt2d(-size, -size)
     seg1 = GCE2d_MakeSegment(p1, p2)
     seg2 = GCE2d_MakeSegment(p2, p3)
     seg3 = GCE2d_MakeSegment(p3, p4)
     seg4 = GCE2d_MakeSegment(p4, p1)
     e1 = BRepBuilderAPI_MakeEdge(seg1.Value(), self.plane)
     e2 = BRepBuilderAPI_MakeEdge(seg2.Value(), self.plane)
     e3 = BRepBuilderAPI_MakeEdge(seg3.Value(), self.plane)
     e4 = BRepBuilderAPI_MakeEdge(seg4.Value(), self.plane)
     aWire = BRepBuilderAPI_MakeWire(e1.Edge(), e2.Edge(), e3.Edge(),
                                     e4.Edge())
     myWireProfile = aWire.Wire()
     return myWireProfile  # TopoDS_Wire
    def test_curves2d_from_offset(self):
        '''Test: curves 2d from offset'''
        array = []
        array.append(gp_Pnt2d(-4, 0))
        array.append(gp_Pnt2d(-7, 2))
        array.append(gp_Pnt2d(-6, 3))
        array.append(gp_Pnt2d(-4, 3))
        array.append(gp_Pnt2d(-3, 5))

        xxx = point2d_list_to_TColgp_Array1OfPnt2d(array)
        SPL1 = Geom2dAPI_PointsToBSpline(xxx).Curve()

        dist = 1
        OC = Geom2d_OffsetCurve(SPL1, dist)
        result = OC.IsCN(2)

        dist2 = 1.5
        OC2 = Geom2d_OffsetCurve(SPL1, dist2)
        result2 = OC2.IsCN(2)
Exemple #17
0
 def on_trimmed(self, u, v):
     '''tests whether the surface at the u,v parameter has been trimmed
     '''
     if self._classify_uv is None:
         self._classify_uv = BRepTopAdaptor_FClass2d(self, 1e-9)
     uv = gp_Pnt2d(u, v)
     if self._classify_uv.Perform(uv) == TopAbs_IN:
         return True
     else:
         return False
Exemple #18
0
def bisect_crvcrv(event=None):
    display.EraseAll()
    ax = gp_Ax22d(gp_Pnt2d(), gp_Dir2d(1, 0), gp_Dir2d(0, -1))
    circ = gp_Circ2d(ax, 5)
    crv1 = GCE2d_MakeCircle(circ).Value()
    edg1 = make_edge2d(crv1, -1.0, 1.0)
    display.DisplayColoredShape(edg1, 'BLUE')

    p1 = gp_Pnt2d(-10, 0)
    p2 = gp_Pnt2d(-10, 10)
    crv2 = GCE2d_MakeLine(p1, p2).Value()
    edg2 = make_edge2d(crv2, -10.0, 10.0)
    display.DisplayColoredShape(edg2, 'GREEN')

    bi = Bisector_BisecCC(crv1, crv2, 50, -5, gp_Pnt2d(0, 0))
    crv_bi = bi.Curve(1)
    edg3 = make_edge2d(crv_bi, -1.0, 1.0)
    display.DisplayColoredShape(edg3, 'RED')
    display.FitAll()
def bisect_linecircle(event=None):
    display.EraseAll()
    ci1 = gp_Circ2d(gp_Ax22d(), 10000)
    li1 = gp_Lin2d(gp_Pnt2d(2000000, 20), gp_Dir2d(0, 1))
    bi = GccAna_CircLin2dBisec(ci1, li1)
    assert bi.IsDone()
    bisec = bi.ThisSolution(1)
    pb = bisec.Parabola()
    display.DisplayShape([make_edge2d(ci1), make_edge2d(li1)])
    display.DisplayColoredShape(make_edge2d(pb), 'BLUE')
    display.FitAll()
Exemple #20
0
 def test_parabola(self):
     '''Test: parabola'''
     # P is the vertex point
     # P and D give the axis of symmetry
     # 6 is the focal length of the parabola
     P = gp_Pnt2d(2., 3.)
     D = gp_Dir2d(4., 5.)
     A = gp_Ax22d(P, D, True)
     Para = gp_Parab2d(A, 6)
     aParabola = GCE2d_MakeParabola(Para)
     gParabola = aParabola.Value()
     aTrimmedCurve = Geom2d_TrimmedCurve(gParabola, -100, 100, True)
Exemple #21
0
def variable_filleting(event=None):
    a_pnt = gp_Pnt(350, 0, 0)
    box_2 = BRepPrimAPI_MakeBox(a_pnt, 200, 200, 200).Shape()
    a_fillet = BRepFilletAPI_MakeFillet(box_2)

    tab_point = TColgp_Array1OfPnt2d(1, 6)
    p_1 = gp_Pnt2d(0., 8.)
    p_2 = gp_Pnt2d(0.2, 16.)
    p_3 = gp_Pnt2d(0.4, 25.)
    p_4 = gp_Pnt2d(0.6, 55.)
    p_5 = gp_Pnt2d(0.8, 28.)
    p_6 = gp_Pnt2d(1., 20.)
    tab_point.SetValue(1, p_1)
    tab_point.SetValue(2, p_2)
    tab_point.SetValue(3, p_3)
    tab_point.SetValue(4, p_4)
    tab_point.SetValue(5, p_5)
    tab_point.SetValue(6, p_6)

    expl3 = list(TopologyExplorer(box_2).edges())

    a_fillet.Add(tab_point, expl3[9])
    a_fillet.Build()
    if a_fillet.IsDone():
        law_evolved_box = a_fillet.Shape()
        display.DisplayShape(law_evolved_box)
    else:
        print("aFillet not done.")
    display.FitAll()
Exemple #22
0
def brep_feat_local_revolution(event=None):
    S = BRepPrimAPI_MakeBox(400., 250., 300.).Shape()
    faces = list(TopologyExplorer(S).faces())
    F1 = faces[2]
    surf = BRep_Tool_Surface(F1)

    D = gp_OX()

    MW1 = BRepBuilderAPI_MakeWire()
    p1 = gp_Pnt2d(100., 100.)
    p2 = gp_Pnt2d(200., 100.)
    aline = GCE2d_MakeLine(p1, p2).Value()
    MW1.Add(BRepBuilderAPI_MakeEdge(aline, surf, 0., p1.Distance(p2)).Edge())

    p1 = gp_Pnt2d(200., 100.)
    p2 = gp_Pnt2d(150., 200.)
    aline = GCE2d_MakeLine(p1, p2).Value()
    MW1.Add(BRepBuilderAPI_MakeEdge(aline, surf, 0., p1.Distance(p2)).Edge())

    p1 = gp_Pnt2d(150., 200.)
    p2 = gp_Pnt2d(100., 100.)
    aline = GCE2d_MakeLine(p1, p2).Value()
    MW1.Add(BRepBuilderAPI_MakeEdge(aline, surf, 0., p1.Distance(p2)).Edge())

    MKF1 = BRepBuilderAPI_MakeFace()
    MKF1.Init(surf, False, 1e-6)
    MKF1.Add(MW1.Wire())
    FP = MKF1.Face()
    breplib_BuildCurves3d(FP)
    MKrev = BRepFeat_MakeRevol(S, FP, F1, D, 1, True)
    F2 = faces[4]
    MKrev.Perform(F2)
    display.EraseAll()
    display.DisplayShape(MKrev.Shape())
    display.FitAll()
    def test_curves2d_from_offset(self):
        '''Test: curves 2d from offset'''
        array = []
        array.append(gp_Pnt2d(-4, 0))
        array.append(gp_Pnt2d(-7, 2))
        array.append(gp_Pnt2d(-6, 3))
        array.append(gp_Pnt2d(-4, 3))
        array.append(gp_Pnt2d(-3, 5))

        xxx = point2d_list_to_TColgp_Array1OfPnt2d(array)
        SPL1 = Geom2dAPI_PointsToBSpline(xxx).Curve()
        self.assertTrue(SPL1 is not None)

        dist = 1
        OC = Geom2d_OffsetCurve(SPL1, dist)
        result = OC.IsCN(2)
        self.assertTrue(result)

        dist2 = 1.5
        OC2 = Geom2d_OffsetCurve(SPL1, dist2)
        result2 = OC2.IsCN(2)
        self.assertTrue(result2)
 def test_parabola(self):
     '''Test: parabola'''
     # P is the vertex point
     # P and D give the axis of symmetry
     # 6 is the focal length of the parabola
     P = gp_Pnt2d(2., 3.)
     D = gp_Dir2d(4., 5.)
     A = gp_Ax22d(P, D, True)
     Para = gp_Parab2d(A, 6)
     aParabola = GCE2d_MakeParabola(Para)
     gParabola = aParabola.Value()
     self.assertIsInstance(gParabola, Geom2d_Parabola)
     aTrimmedCurve = Geom2d_TrimmedCurve(gParabola, -100, 100, True)
     self.assertIsNotNone(aTrimmedCurve)
     self.assertFalse(aTrimmedCurve.IsNull())
 def test_parabola(self):
     """Test: parabola"""
     # P is the vertex point
     # P and D give the axis of symmetry
     # 6 is the focal length of the parabola
     P = gp_Pnt2d(2.0, 3.0)
     D = gp_Dir2d(4.0, 5.0)
     A = gp_Ax22d(P, D, True)
     Para = gp_Parab2d(A, 6)
     aParabola = GCE2d_MakeParabola(Para)
     gParabola = aParabola.Value()
     self.assertIsInstance(gParabola, Geom2d_Parabola)
     aTrimmedCurve = Geom2d_TrimmedCurve(gParabola, -100, 100, True)
     self.assertIsNotNone(aTrimmedCurve)
     self.assertFalse(aTrimmedCurve is None)
    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()
Exemple #27
0
def parabola(event=None):
    # P is the vertex point
    # P and D give the axis of symmetry
    # 6 is the focal length of the parabola
    a_pnt = gp_Pnt2d(2, 3)
    a_dir = gp_Dir2d(4, 5)
    an_ax = gp_Ax22d(a_pnt, a_dir, True)
    para = gp_Parab2d(an_ax, 6)
    display.DisplayShape(a_pnt)
    display.DisplayMessage(a_pnt, "P")

    aParabola = GCE2d_MakeParabola(para)
    gParabola = aParabola.Value()

    aTrimmedCurve = Geom2d_TrimmedCurve(gParabola, -100, 100, True)

    display.DisplayShape(aTrimmedCurve, update=True)
Exemple #28
0
    def _edge_to_svg_polyline(self, topods_edge,scale=1):
        """ Returns a svgwrite.Path for the edge, and the 2d bounding box
        """
        unit = self.UNIT
        tol = self.TOL

        points_3d = discretize_edge(topods_edge, tol)
        points_2d = []
        box2d = Bnd_Box2d()

        for point in points_3d:
            # we tak only the first 2 coordinates (x and y, leave z)
            x_p = point[0]
            y_p = - point[1]
            box2d.Add(gp_Pnt2d(x_p, y_p))
            points_2d.append((x_p, y_p))

        return svgwrite.shapes.Polyline(points_2d, fill="none", class_='vectorEffectClass'), box2d
Exemple #29
0
    def _calc_biquadratic_parabola_point(self, lpt, L, R, ccw):
        x = lpt
        if x <= (L / 2):
            y = x ** 4 / (6 * R * L ** 2)
        else:

            yterm_1 = (-1 * x ** 4) / (6 * R * L ** 2)
            yterm_2 = (2 * x ** 3) / (3 * R * L)
            yterm_3 = x ** 2 / (2 * R)
            yterm_4 = (L * x) / (6 * R)
            yterm_5 = L ** 2 / (48 * R)

            y = yterm_1 + yterm_2 - yterm_3 + yterm_4 - yterm_5

        if not ccw:
            y = -y

        return gp_Pnt2d(x, y)
    def test_point_from_curve(self):
        '''Test: point from curve'''
        radius, abscissa = 5., 3.
        C = Geom2d_Circle(gp_OX2d(), radius, True)
        GAC = Geom2dAdaptor_Curve(C)
        UA = GCPnts_UniformAbscissa(GAC, abscissa)

        aSequence = []
        if UA.IsDone():
            N = UA.NbPoints()
            for count in range(1, N + 1):
                P = gp_Pnt2d()
                C.D0(UA.Parameter(count), P)
                Parameter = UA.Parameter(count)
                self.assertIsInstance(Parameter, float)
                aSequence.append(P)

        Abscissa = UA.Abscissa()
        self.assertEqual(Abscissa, abscissa)
Exemple #31
0
    def test_point_from_curve(self):
        '''Test: point from curve'''
        radius, abscissa = 5., 3.
        C = Geom2d_Circle(gp_OX2d(), radius, True)
        GAC = Geom2dAdaptor_Curve(C)
        UA = GCPnts_UniformAbscissa(GAC, abscissa)

        aSequence = []
        if UA.IsDone():
            N = UA.NbPoints()
            for count in range(1, N + 1):
                P = gp_Pnt2d()
                C.D0(UA.Parameter(count), P)
                Parameter = UA.Parameter(count)
                self.assertIsInstance(Parameter, float)
                aSequence.append(P)

        Abscissa = UA.Abscissa()
        self.assertEqual(Abscissa, abscissa)
Exemple #32
0
    def _calc_clothoid_curve_point(self, lpt, L, R, ccw):
        RL = R * L
        xterm_1 = 1
        xterm_2 = lpt ** 4 / (40 * RL ** 2)
        xterm_3 = lpt ** 8 / (3456 * RL ** 4)
        xterm_4 = lpt ** 12 / (599040 * RL ** 6)
        x = lpt * (xterm_1 - xterm_2 + xterm_3 - xterm_4)

        factor = lpt ** 3 / (6 * RL)
        yterm_1 = 1
        yterm_2 = lpt ** 4 / (56 * RL ** 2)
        yterm_3 = lpt ** 8 / (7040 * RL ** 4)
        yterm_4 = lpt ** 12 / (1612800 * RL ** 6)

        y = factor * (yterm_1 - yterm_2 + yterm_3 - yterm_4)

        if not ccw:
            y = -y

        return gp_Pnt2d(x, y)
Exemple #33
0
    def _calc_cosine_curve_point(self, lpt, L, R, ccw):
        pi = math.pi
        psi_x = (pi * lpt) / L

        xterm_1 = (L ** 2) / (8.0 * pi ** 2 * R ** 2)
        xterm_2 = L / pi
        xterm_3 = psi_x ** 3 / (3.0)
        xterm_4 = psi_x / (2.0)
        xterm_5 = (math.sin(psi_x) * math.cos(psi_x)) / (2.0)
        xterm_6 = psi_x * math.cos(psi_x)

        x = lpt - xterm_1 * xterm_2 * (xterm_3 + xterm_4 - xterm_5 - (2.0 * xterm_6))

        # TODO: code for y - coordinate
        y = 0

        if not ccw:
            y = -y

        return gp_Pnt2d(x, y)
Exemple #34
0
def edge_to_svg_polyline(topods_edge, tol=0.1, unit="mm"):
    """Returns a svgwrite.Path for the edge, and the 2d bounding box"""
    unit_factor = 1  # by default

    if unit == "mm":
        unit_factor = 1
    elif unit == "m":
        unit_factor = 1e3

    points_3d = discretize_edge(topods_edge, tol)
    points_2d = []
    box2d = Bnd_Box2d()

    for point in points_3d:
        # we tak only the first 2 coordinates (x and y, leave z)
        x_p = -point[0] * unit_factor
        y_p = point[1] * unit_factor
        box2d.Add(gp_Pnt2d(x_p, y_p))
        points_2d.append((x_p, y_p))

    return svgwrite.shapes.Polyline(points_2d, fill="none"), box2d
Exemple #35
0
def sample_point(face):
    #    randomly choose a point from F
    u_min, u_max, v_min, v_max = breptools_UVBounds(face)
    u = random.uniform(u_min, u_max)
    v = random.uniform(v_min, v_max)

    itool = IntTools_FClass2d(face, 1e-6)
    while itool.Perform(gp_Pnt2d(u,v)) != 0:
        print('outside')
        u = random.uniform(u_min, u_max)
        v = random.uniform(v_min, v_max)

    P = BRepAdaptor_Surface(face).Value(u, v)

#   the normal
    surf = BRep_Tool_Surface(face)
    D = GeomLProp_SLProps(surf,u,v,1,0.01).Normal()
    if face.Orientation() == TopAbs_REVERSED:
        D.Reverse()

    return P, D
    def test_bspline(self):
        '''Test: bspline'''
        array = []
        array.append(gp_Pnt2d(0, 0))
        array.append(gp_Pnt2d(1, 2))
        array.append(gp_Pnt2d(2, 3))
        array.append(gp_Pnt2d(4, 3))
        array.append(gp_Pnt2d(5, 5))

        xxx = point2d_list_to_TColgp_Array1OfPnt2d(array)
        SPL1 = Geom2dAPI_PointsToBSpline(xxx).Curve()
        self.assertTrue(SPL1 is not None)

        harray = TColgp_HArray1OfPnt2d(1, 5)
        harray.SetValue(1, gp_Pnt2d(7 + 0, 0))
        harray.SetValue(2, gp_Pnt2d(7 + 1, 2))
        harray.SetValue(3, gp_Pnt2d(7 + 2, 3))
        harray.SetValue(4, gp_Pnt2d(7 + 4, 3))
        harray.SetValue(5, gp_Pnt2d(7 + 5, 5))

        anInterpolation = Geom2dAPI_Interpolate(harray, False, 0.01)
        anInterpolation.Perform()
        SPL2 = anInterpolation.Curve()
        self.assertTrue(SPL2 is not None)

        harray2 = TColgp_HArray1OfPnt2d(1, 5)
        harray2.SetValue(1, gp_Pnt2d(11 + 0, 0))
        harray2.SetValue(2, gp_Pnt2d(11 + 1, 2))
        harray2.SetValue(3, gp_Pnt2d(11 + 2, 3))
        harray2.SetValue(4, gp_Pnt2d(11 + 4, 3))
        harray2.SetValue(5, gp_Pnt2d(11 + 5, 5))

        anInterpolation2 = Geom2dAPI_Interpolate(harray2, True, 0.01)
        anInterpolation2.Perform()
        SPL3 = anInterpolation2.Curve()
        self.assertTrue(SPL3 is not None)
        i = 0
        for P in array:
            i = i+1
            make_vertex(P)
        for j in range(harray.Lower(), harray.Upper()+1):
            i = i+1
            P = harray.Value(j)
            make_vertex(P)

        for j in range(harray2.Lower(), harray2.Upper()+1):
            i = i+1
            P = harray2.Value(j)
            make_vertex(P)