PythonOCC基础使用:建模——基础三维实体(球体,长方体,棱柱/台/锥,圆柱/锥/台,环形)

下面会列举一些基本三维图形命令:

  • 长方体
  • 在这里插入图片描述
from OCC.Core.BRepPrimAPI import BRepPrimAPI_MakeBox
from OCC.Display.OCCViewer import rgb_color
#长方体
my_box = BRepPrimAPI_MakeBox (10,10,10).Shape()
if __name__ == "__main__":
    from OCC.Display.SimpleGui import init_display
    display, start_display, add_menu, add_function_to_menu = init_display()
    display.DisplayShape(my_box,update=True,color=rgb_color(0,1,0))
    start_display()
  • 球体
  • 在这里插入图片描述
from OCC.Core.BRepPrimAPI import BRepPrimAPI_MakeSphere
from OCC.Core.gp import gp_Pnt
from OCC.Display.OCCViewer import rgb_color
#qiu
center=gp_Pnt(5,5,10)
radius=19
my_sphere =BRepPrimAPI_MakeSphere(center ,radius).Shape()
if __name__ == "__main__":
    from OCC.Display.SimpleGui import init_display
    display, start_display, add_menu, add_function_to_menu = init_display()
    display.DisplayShape(my_sphere, update=True)
    display.DisplayShape(my_sphere, update=True, color=rgb_color(0, 1,0 ))
    start_display()
  • 圆锥(gp_Ax2可以理解为射线,是由一点和法线组成)
  • 在这里插入图片描述
from OCC.Core.BRepPrimAPI import BRepPrimAPI_MakeSphere, BRepPrimAPI_MakeCone
from OCC.Core.gp import gp_Pnt, gp_Ax2, gp_Dir
from OCC.Display.OCCViewer import rgb_color
#圆锥
my_cone = BRepPrimAPI_MakeCone(1,0,4).Shape()
my_cone=BRepPrimAPI_MakeCone(gp_Ax2 (gp_Pnt(0,0,0),gp_Dir (0,0,-1)),0,2,4).Shape( )
if __name__ == "__main__":
    from OCC.Display.SimpleGui import init_display
    display, start_display, add_menu, add_function_to_menu = init_display()
    display.DisplayShape(my_cone, update=True)
    # display.DisplayShape(my_cone, update=True, color=rgb_color(0, 1, 1 ))
    start_display()
  • 圆台
  • 在这里插入图片描述
from OCC.Core.BRepPrimAPI import BRepPrimAPI_MakeSphere, BRepPrimAPI_MakeCone
from OCC.Core.gp import gp_Pnt, gp_Ax2, gp_Dir
from OCC.Display.OCCViewer import rgb_color
#圆台
my_cone = BRepPrimAPI_MakeCone(1,0,4).Shape()
my_cone=BRepPrimAPI_MakeCone(gp_Ax2 (gp_Pnt(0,0,0),gp_Dir (0,0,-1)),1,2,4).Shape( )
if __name__ == "__main__":
    from OCC.Display.SimpleGui import init_display
    display, start_display, add_menu, add_function_to_menu = init_display()
    display.DisplayShape(my_cone, update=True)
    # display.DisplayShape(my_cone, update=True, color=rgb_color(0, 1, 1 ))
    start_display()
  • 圆柱
  • 在这里插入图片描述
from OCC.Core.BRepPrimAPI import BRepPrimAPI_MakeCylinder
#圆柱
my_cylinder=BRepPrimAPI_MakeCylinder(10,50).Shape()
if __name__ == "__main__":
    from OCC.Display.SimpleGui import init_display
    display, start_display, add_menu, add_function_to_menu = init_display()
    display.DisplayShape(my_cylinder,update=True)
    start_display()
  • 环形
  • 在这里插入图片描述
from OCC.Core.BRepPrimAPI import BRepPrimAPI_MakeTorus
from OCC.Core.gp import gp_Pnt
from OCC.Core.gp import gp_Ax2,gp_Dir
my_Torus = BRepPrimAPI_MakeTorus(gp_Ax2 (gp_Pnt (0,0,2),gp_Dir (0,0,1)),0.55,0.1).Shape()
if __name__ == "__main__":
    from OCC.Display.SimpleGui import init_display
    display, start_display, add_menu, add_function_to_menu = init_display()
    display.DisplayShape(my_Torus, update=True)
    start_display()
  • 棱锥
  • 在这里插入图片描述
my_wedge = BRepPrimAPI_MakeWedge(gp_Ax2(gp_Pnt(4, 0,4), gp_Dir(1,1,0)),4,4,4,2,2,2,2).Shape()
  • 棱台
  • 在这里插入图片描述
my_wedge = BRepPrimAPI_MakeWedge(gp_Ax2 (gp_Pnt (-4,-8,-4),gp_Dir (0,0,1)),4,4,8,1,1,3,7).Shape()
  • 棱柱
  • 在这里插入图片描述
my_wedge1 = BRepPrimAPI_MakeWedge(gp_Ax2(gp_Pnt(2, -6, -4), gp_Dir(0, 0, 1)), 2, 3, 4, 1).Shape()
  • 8
    点赞
  • 24
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
PythonOCC是一个基于Python的开源CAD/CAM/CAE解决方案。它提供了一组强大的工具和库,用于创建、处理和分析CAD模型。在PythonOCC中,基础建模指令非常重要,这些指令可以用来创建几何实体和进行基本的几何操作。以下是一些常用的基础建模指令: 1. 点:用于创建3D空间中的点。 ```python from OCC.gp import gp_Pnt # 创建一个点 point = gp_Pnt(0, 0, 0) ``` 2. 直线:用于创建一条直线。 ```python from OCC.gp import gp_Pnt, gp_Dir, gp_Lin # 创建一条直线 point = gp_Pnt(0, 0, 0) direction = gp_Dir(0, 0, 1) # 方向矢量,垂直于 XY 平面 line = gp_Lin(point, direction) ``` 3. 圆:用于创建一个圆。 ```python from OCC.gp import gp_Circ, gp_Ax2, gp_Pnt # 创建一个圆 center = gp_Pnt(0, 0, 0) radius = 10 axis = gp_Ax2(center, gp_Dir(0, 0, 1)) # 方向矢量,垂直于 XY 平面 circle = gp_Circ(axis, radius) ``` 4. 矩形:用于创建一个矩形。 ```python from OCC.gp import gp_Pnt, gp_Ax2, gp_Dir, gp_Lin, gp_Pln, gp_Mat # 创建一个矩形 point = gp_Pnt(0, 0, 0) direction = gp_Dir(0, 0, 1) # 方向矢量,垂直于 XY 平面 line = gp_Lin(point, direction) plane = gp_Pln(gp_Pnt(0, 0, 0), gp_Dir(0, 0, 1)) mat = gp_Mat() mat.SetTranslation(gp_Vec(10, 10, 0)) line2 = line.Transformed(mat) rectangle = BRepBuilderAPI_MakeEdge(line, line2).Edge() ``` 5. 球体:用于创建一个球体。 ```python from OCC.gp import gp_Sphere, gp_Pnt # 创建一个球体 center = gp_Pnt(0, 0, 0) radius = 10 sphere = gp_Sphere(center, radius) ``` 这些指令只是PythonOCC基础建模指令的一部分,你可以通过PythonOCC的官方文档和示例来学习更多指令。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值