PythonOCC基础使用:建模——矩阵变换(平移/旋转/缩放/镜像)

此处特别感谢小昌做出的贡献!

1.平移

效果图:
在这里插入图片描述

from OCC.Core.BRepPrimAPI import BRepPrimAPI_MakeCone
from OCC.Core.TopLoc import TopLoc_Location
from OCC.Core.TopoDS import TopoDS_Shape
from OCC.Core.gp import gp_Pnt, gp_Trsf, gp_Vec, gp_Ax1, gp_Dir
from OCC.Display.OCCViewer import rgb_color

my_cone = BRepPrimAPI_MakeCone(1,0,4).Shape()
cone=TopoDS_Shape(my_cone)
T=gp_Trsf()
T.SetTranslation(gp_Vec(0,5,0))
loc=TopLoc_Location(T)
cone.Location(loc)

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,color=rgb_color(1,0,0))
    display.DisplayShape(cone, update=True,color=rgb_color(0,0,1))
    start_display()

2.旋转

效果图:
在这里插入图片描述

from OCC.Core.GeomAPI import GeomAPI_Interpolate
from OCC.Core.BRepPrimAPI import BRepPrimAPI_MakeCone
from OCC.Core.TopoDS import TopoDS_Shape
from OCC.Core.TColgp import TColgp_HArray1OfPnt
from OCC.Core.gp import gp_Pnt, gp_Ax1, gp_Dir, gp_Circ, gp_Elips,gp_Trsf,gp_Vec
from OCC.Core.TopLoc import TopLoc_Location
from OCC.Core.GC import GC_MakeSegment, GC_MakeCircle, GC_MakeArcOfCircle, GC_MakeEllipse,GC_MakeRotation
from OCC.Core.BRepBuilderAPI import BRepBuilderAPI_MakeEdge, BRepBuilderAPI_MakeWire
from OCC.Display.OCCViewer import rgb_color
#旋转
my_cone = BRepPrimAPI_MakeCone(1,0,4).Shape()
cone=TopoDS_Shape(my_cone)
T1=gp_Trsf()
T=gp_Ax1(gp_Pnt(0, 1, 0), gp_Dir(0, 6, 4))
T1.SetRotation(T,1)
coneLoc=TopLoc_Location(T1)
my_cone.Move(coneLoc)

if __name__ == "__main__":
    from OCC.Display.SimpleGui import init_display
    display, start_display, add_menu, add_function_to_menu = init_display()
    display.DisplayShape(cone,update=True,color=rgb_color(0,0,0))
    display.DisplayShape(my_cone, update=True,color=rgb_color(1,0,0))
    start_display()

3.缩放

效果图:
在这里插入图片描述

from OCC.Core.GeomAPI import GeomAPI_Interpolate
from OCC.Core.BRepPrimAPI import BRepPrimAPI_MakeCone
from OCC.Core.TopoDS import TopoDS_Shape
from OCC.Core.TColgp import TColgp_HArray1OfPnt
from OCC.Core.gp import gp_Pnt, gp_Ax1, gp_Dir, gp_Circ, gp_Elips,gp_Trsf,gp_Vec
from OCC.Core.TopLoc import TopLoc_Location
from OCC.Core.GC import GC_MakeSegment, GC_MakeCircle, GC_MakeArcOfCircle, GC_MakeEllipse,GC_MakeRotation
from OCC.Core.BRepBuilderAPI import BRepBuilderAPI_MakeEdge, BRepBuilderAPI_MakeWire
from OCC.Display.OCCViewer import rgb_color
#缩放
my_cone = BRepPrimAPI_MakeCone(1,0,4).Shape()
cone=TopoDS_Shape(my_cone)
T1=gp_Trsf()
T=gp_Pnt(0, 20, 0)
T1.SetScale(T,5)
coneLoc=TopLoc_Location(T1)
my_cone.Move(coneLoc)

if __name__ == "__main__":
    from OCC.Display.SimpleGui import init_display
    display, start_display, add_menu, add_function_to_menu = init_display()
    display.DisplayShape(cone,update=True,color=rgb_color(0,0,0))
    display.DisplayShape(my_cone, update=True,color=rgb_color(1,0,0))
    start_display()

4.镜像

效果图:
在这里插入图片描述

from OCC.Core.TColgp import TColgp_HArray1OfPnt
from OCC.Core.BRepPrimAPI import BRepPrimAPI_MakeCone
from OCC.Core.gp import gp_Pnt, gp_Ax1, gp_Dir, gp_Circ, gp_Elips,gp_Trsf,gp_Vec
from OCC.Core.TopLoc import TopLoc_Location
from OCC.Core.TopoDS import TopoDS_Shape
from OCC.Core.GC import GC_MakeSegment, GC_MakeCircle, GC_MakeArcOfCircle, GC_MakeEllipse,GC_MakeRotation
from OCC.Core.BRepBuilderAPI import BRepBuilderAPI_MakeEdge, BRepBuilderAPI_MakeWire
from OCC.Display.OCCViewer import rgb_color
#镜像
my_cone = BRepPrimAPI_MakeCone(1,0,4).Shape()
cone=TopoDS_Shape(my_cone)
T1 = gp_Trsf()
T=gp_Ax1(gp_Pnt(0,6,0),gp_Dir(0,4,1))
T1.SetMirror(T)
coneLoc=TopLoc_Location(T1)
my_cone.Move(coneLoc)

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, color=rgb_color( 1, 0, 0 ) )
    display.DisplayShape(cone,update=True,color=rgb_color(0,0,0))
    start_display()

5.以上效果叠加(占坑)

参考链接:http://www.cppblog.com/eryar/archive/2015/01/22/209612.html

  • 2
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值