pythonocc 画8个相切球

from OCC.Core.BRep import BRep_Builder
from OCC.Core.TopoDS import TopoDS_Compound
from OCC.Core.BRepPrimAPI import BRepPrimAPI_MakeSphere
from OCC.Core.gp import gp_Pnt
from OCC.Core.STEPControl import STEPControl_Writer, STEPControl_StepModelType
from OCC.Core.IFSelect import IFSelect_RetDone
from OCC.Display.SimpleGui import init_display
# 定义球的半径
radius = 10.0

# 定义球心的位置,使得它们在空间中排列成一个立方体的八个顶点
centers = [
    gp_Pnt(-radius, -radius, -radius),
    gp_Pnt(radius, -radius, -radius),
    gp_Pnt(-radius, radius, -radius),
    gp_Pnt(radius, radius, -radius),
    gp_Pnt(-radius, -radius, radius),
    gp_Pnt(radius, -radius, radius),
    gp_Pnt(-radius, radius, radius),
    gp_Pnt(radius, radius, radius)
]

# 创建八个球
spheres = [BRepPrimAPI_MakeSphere(center, radius).Shape() for center in centers]

# 创建一个复合形状来包含所有球
builder = BRep_Builder()
compound = TopoDS_Compound()
builder.MakeCompound(compound)

for sphere in spheres:
    builder.Add(compound, sphere)

# 导出为 STEP 文件
step_writer = STEPControl_Writer()
status = step_writer.Transfer(compound, STEPControl_StepModelType.STEPControl_AsIs)
if status == IFSelect_RetDone:
    step_writer.Write("eight_connected_spheres.stp")
    print("文件已成功导出为 eight_connected_spheres.stp")
else:
    print("导出失败")

display, start_display, add_menu, add_function_to_menu = init_display()

# 将所有球体添加到显示窗口
for sphere in spheres:
    display.DisplayShape(sphere, update=True)

# 启动事件循环以保持窗口打开
start_display()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值