圆形
from OCC.Core.GC import GC_MakeCircle
from OCC.Core.gp import gp_Pnt
from OCC.Core.gp import gp_Ax2,gp_Dir
from OCC.Display.OCCViewer import rgb_color
#圆形
Circle=GC_MakeCircle(gp_Ax2 (gp_Pnt(0,0,5),gp_Dir (0,0,-1)),8).Value()
if __name__ == "__main__":
from OCC.Display.SimpleGui import init_display
display, start_display, add_menu, add_function_to_menu = init_display()
display.DisplayShape(Circle,update=True,color=rgb_color(0,0,1))
start_display()
- 线段
from OCC.Core.gp import gp_Pnt
from OCC.Core.GC import GC_MakeSegment
from OCC.Core.BRepBuilderAPI import BRepBuilderAPI_MakeEdge, BRepBuilderAPI_MakeWire
from OCC.Display.OCCViewer import rgb_color
# 函数作用:通过两点生成线段
# 输入:两点
# 输出:线段
aSegment = GC_MakeSegment(gp_Pnt(1,1,1), gp_Pnt(1,10,1))
anEdge = BRepBuilderAPI_MakeEdge(aSegment.Value())
aWire = BRepBuilderAPI_MakeWire(anEdge.Edge())
if __name__ == "__main__":
from OCC.Display.SimpleGui import init_display
display, start_display, add_menu, add_function_to_menu = init_display()
display.DisplayShape(aWire.Shape(), update=True,color=rgb_color(1,0,0))
start_display()
以及从2d转到3d的方法:
from OCC.Core.BRepBuilderAPI import BRepBuilderAPI_MakeWire, BRepBuilderAPI_MakeEdge
from OCC.Core.BRepPrimAPI import BRepPrimAPI_MakeCylinder
from OCC.Core.GCE2d import GCE2d_MakeSegment
from OCC.Core.GeomAPI import geomapi_To3d
from OCC.Core.gp import gp_Pnt2d, gp_Pln, gp_Pnt, gp_Dir
from OCC.Display.SimpleGui import init_display
sideLength=20
l1 = GCE2d_MakeSegment(gp_Pnt2d(-sideLength / 2, sideLength / 2), gp_Pnt2d(sideLength / 2, sideLength / 2))
l2 = GCE2d_MakeSegment(gp_Pnt2d(sideLength / 2, sideLength / 2), gp_Pnt2d(sideLength / 2, -sideLength / 2)