Ejemplo n.º 1
0
    def __init__(self):
        plotocc.__init__(self)
        self.axs = gp_Ax3()

        p_array = TColgp_Array1OfPnt(1, 100)
        for idx, pt in enumerate(np.linspace(-2.0, 2.0, 100)):
            pnt = gp_Pnt(300 * np.sin(pt), 100 * np.cos(3 * pt), 0)
            p_array.SetValue(idx + 1, pnt)
        api = GeomAPI_PointsToBSpline(p_array)
        self.curv = api.Curve()
        print(self.curv)

        api = BRepOffsetAPI_ThruSections()
        api.SetSmoothing(True)
        num_list = [
            3, 3, 3, 3, 3,
            6, 6, 6, 6, 6, 6, 6, 6, 6,
            7, 7, 7, 7, 7, 7, 7, 7,
            4, 4, 4
        ]
        p1, v1, v2 = gp_Pnt(), gp_Vec(), gp_Vec()
        for idx, pt in enumerate(np.linspace(0.0, 0.5, len(num_list))):
            GeomLProp_CurveTool.D2(self.curv, pt, p1, v1, v2)
            v3 = v1.Crossed(v2)
            axis = gp_Ax3(p1, vec_to_dir(v1), vec_to_dir(v2))
            poly = self.make_PolyWire(num=num_list[idx], radi=20, axs=axis)
            api.AddWire(poly)
            self.show_axs_pln(axis, scale=10)
            self.display.DisplayShape(poly)
        api.Build()
        self.display.DisplayShape(api.Shape())
        write_step_file(api.Shape(), "./tmp/ThruPipe_Hex.stp")

        api = BRepOffsetAPI_ThruSections()
        # api.SetSmoothing(True)
        p1, v1, v2 = gp_Pnt(), gp_Vec(), gp_Vec()
        for idx, pt in enumerate(np.linspace(0.55, 1.0, 20)):
            GeomLProp_CurveTool.D2(self.curv, pt, p1, v1, v2)
            v3 = v1.Crossed(v2)
            axis = gp_Ax3(p1, vec_to_dir(v1), vec_to_dir(v2))
            shft = 90 * pt
            poly = self.make_Ellip(rxy=[15, 10], shft=shft, axs=axis)
            api.AddWire(poly)
            self.display.DisplayShape(poly)
        api.Build()
        self.display.DisplayShape(api.Shape())
        write_step_file(api.Shape(), "./tmp/ThruPipe_Ellip.stp")
Ejemplo n.º 2
0
    def __init__(self):
        plotocc.__init__(self)
        self.axs = gp_Ax3()

        self.circle = Geom_Circle(gp_Circ(self.axs.Ax2(), 100))
        p0, v1, v2 = gp_Pnt(), gp_Vec(), gp_Vec()
        GeomLProp_CurveTool.D2(self.circle, 0, p0, v1, v2)
        self.poly_axs = gp_Ax3(p0, vec_to_dir(v1))
        for num in range(4, 9):
            self.poly = self.make_PolyWire(
                num=num, radi=20.0, axs=self.poly_axs)

            self.base = self.make_Thru(50)
            self.display.DisplayShape(
                self.base, transparency=0.7, color="BLUE")
            write_step_file(self.base, self.tmpdir +
                            "ThruSurf_{:d}.stp".format(num))
Ejemplo n.º 3
0
 def check_ground(self):
     if len(self.pts) != 1:
         ray = spl_2pnt(self.pts[-2], self.pts[-1])
         vec = gp_Vec(self.pts[-2], self.pts[-1])
         self.p_trce.Perform(ray, self.h_surf)
         if self.p_trce.NbPoints() != 0 and vec.Z() < 0:
             print()
             uvw = self.p_trce.Parameters(1)
             u, v, w = uvw
             p0, v0 = gp_Pnt(), gp_Vec()
             GeomLProp_CurveTool.D1(ray, w, p0, v0)
             p1, vx, vy = gp_Pnt(), gp_Vec(), gp_Vec()
             GeomLProp_SurfaceTool.D1(self.h_surf, u, v, p1, vx, vy)
             vz = vx.Crossed(vy)
             self.pts[-1] = p0
             print(self.r.t, w, p0)
             print(v0)
             print(gp_Vec(self.pts[-2], self.pts[-1]))
             norm = gp_Ax3(p1, vec_to_dir(vz), vec_to_dir(vx))
             v1 = v0
             v1.Mirror(norm.Ax2())
             self.r.set_initial_value(self.gen_condition(p0, v1),
                                      self.r.t + self.dt)
Ejemplo n.º 4
0
 def _local_properties(self):
     self._lprops_curve_tool = GeomLProp_CurveTool()
     self._local_properties_init = True
Ejemplo n.º 5
0
    obj.show_axs_pln(scale=1)

    pt = np.linspace(0, 1, 100)
    num = 2
    omg = 0.5
    idx = 2
    pts = []
    for t in pt[:-1]:
        ft = 1 - (idx - 1) * np.sin(2 * np.pi * t)
        if ft >= 1:
            ut = omg**ft
        else:
            ut = 1 - (1 - omg)**(2 - ft)
        x = np.cos(num * ut * 2 * np.pi)
        y = np.sin(num * ut * 2 * np.pi)
        #z = 2 * (t % 0.5)
        z = 2 * t
        pnt = gp_Pnt(x, y, z)
        pts.append(pnt)

    crv_p, crv = spl_curv_pts(pts)

    print(GeomLProp_CurveTool.FirstParameter(crv))
    print(GeomLProp_CurveTool.LastParameter(crv))

    obj.display.DisplayShape(crv)
    for pnt in pts[::10]:
        obj.display.DisplayShape(pnt)

    obj.show()
Ejemplo n.º 6
0
    trf.SetDisplacement(gp_Ax3(), axs)
    return trf


if __name__ == '__main__':
    obj = plotocc(touch=True)
    obj.show_axs_pln(scale=5)

    px = np.linspace(-1, 1, 100) * 2 * np.pi * 2.5
    py = np.linspace(-1, 1, 150) * 2 * np.pi * 2.5
    mesh = np.meshgrid(px, py)
    surf1 = np.sin(mesh[0] / 4) * 0.5
    surf2 = np.sin(mesh[1] / 2)
    face1 = spl_face(*mesh, surf1)
    face2 = spl_face(*mesh, surf2)

    api = GeomAPI_IntSS(BRep_Tool.Surface(face1), BRep_Tool.Surface(face2),
                        1.0e-7)
    print(api.NbLines())

    obj.display.DisplayShape(face1)
    obj.display.DisplayShape(face2)
    for i in range(api.NbLines()):
        crv = api.Line(i + 1)
        p0 = GeomLProp_CurveTool.FirstParameter(crv)
        p1 = GeomLProp_CurveTool.LastParameter(crv)
        print(p0, p1)
        obj.display.DisplayShape(crv)

    obj.show()
Ejemplo n.º 7
0
    p0 = gp_Pnt(10, 10, 50)
    p1 = gp_Pnt(-20, -20, -50)
    pts, crv = spl_curv_pts([p0, p1])
    pln = make_plane(vec_normal=gp_Vec(0, 1, 1))
    h_surf = BRep_Tool.Surface(pln)
    api = GeomAPI_IntCS(crv, h_surf)
    print(api.IsDone())
    print(api.NbSegments())

    uvw = api.Parameters(1)
    u, v, w = uvw
    pnt_crv = gp_Pnt()
    pnt_1st = gp_Pnt()
    pnt_2nd = gp_Pnt()
    pnt_srf = gp_Pnt()
    GeomLProp_CurveTool.Value(crv, w, pnt_crv)
    GeomLProp_CurveTool.Value(crv, 0, pnt_1st)
    GeomLProp_CurveTool.Value(crv, 1, pnt_2nd)
    GeomLProp_SurfaceTool.Value(h_surf, u, v, pnt_srf)
    print(uvw)
    print(pnt_crv)
    print(pnt_1st)
    print(pnt_2nd)
    print(pnt_srf)

    pnt_crv = gp_Pnt()
    vec_crv = gp_Vec()
    GeomLProp_CurveTool.D1(crv, w, pnt_crv, vec_crv)
    print(pnt_crv)
    print(vec_crv)
    print(gp_Vec(p0, p1))