freecad X方向相交 及面积计算
1
#构建X方向切割面CX; import FreeCAD as App import FreeCADGui as Gui import Part doc = App.activeDocument() if doc is None: doc = App.newDocument("CutMacro") # 清理旧对象(如果已存在) for obj in doc.Objects: doc.removeObject(obj.Name) cylinder1 = doc.addObject("Part::Cylinder", "Cylinder1") cylinder1.Radius = 15 # D30 -> 半径15 cylinder1.Height = 70 cylinder1.Placement.Base = App.Vector(0, 0, 0) plane = doc.addObject("Part::Box", "CX") plane.Length = 1 # X方向厚度 plane.Width = 40 # Y方向 plane.Height = 70 # Z方向 plane.Placement.Base = App.Vector(0, -20, 0) # 位置固定 doc.recompute() # 执行布尔相交运算 common = doc.addObject("Part::Common", "Intersection") common.Base = cylinder1 common.Tool = plane doc.recompute() # 获取交集形状并输出基本信息 shape = common.Shape print("=== 圆柱与切割面 CX 的交集信息 ===") print(f"体积 Volume: {shape.Volume} mm³") print(f"边界框 Bounds(min/max的坐标范围): {shape.BoundBox}") print(f"表面积 Area: {shape.Area} mm²") print(f"是否为有效形状: {shape.isValid()}") print(f"总边长(线长度): {shape.Length}") center = shape.CenterOfGravity print("=== 交集质心坐标 ===") print(f"X: {center.x:.2f} mm") print(f"Y: {center.y:.2f} mm") print(f"Z: {center.z:.2f} mm") print(f"具体边界坐标: {shape.BoundBox.XMin}") print("=== 每个面的面积 ===") for i, face in enumerate(shape.Faces): print(f"Face {i+1} area: {face.Area}")
2
3
4
5
6

浙公网安备 33010602011771号