2d
from OCC
.Core
.Geom2dAPI
import Geom2dAPI_Interpolate
from OCC
.Core
.TColgp
import TColgp_HArray1OfPnt2d
from OCC
.Core
.gp
import gp_Pnt2d
from OCC
.Display
.SimpleGui
import init_displaypoints
=[]points
=TColgp_HArray1OfPnt2d
(1,3)
p1
=gp_Pnt2d
(0,1)
p2
=gp_Pnt2d
(2,1)
p3
=gp_Pnt2d
(6,-3)points
.SetValue
(1,p1
)
points
.SetValue
(2,p2
)
points
.SetValue
(3,p3
)
interp
=Geom2dAPI_Interpolate
(points
,False,0.0001)
interp
.Perform
()display
, start_display
, add_menu
, add_function_to_menu
= init_display
()display
.DisplayShape
(interp
.Curve
(),update
=True)
display
.DisplayShape
(p1
)
display
.DisplayShape
(p2
)
display
.DisplayShape
(p3
)start_display
()
Geom2dAPI類下的 Geom2dAPI_PointsToBSpline 可以允許建立2D BSpline曲線, 這用來逼近一系列的點。
from OCC
.Core
.Geom2dAPI
import Geom2dAPI_PointsToBSpline
from OCC
.Core
.TColgp
import TColgp_Array1OfPnt2d
from OCC
.Core
.gp
import gp_Pnt2d
from OCC
.Display
.SimpleGui
import init_displaypoints
=TColgp_Array1OfPnt2d
(1,3)
p1
=gp_Pnt2d
(0,1)
p2
=gp_Pnt2d
(2,1)
p3
=gp_Pnt2d
(6,-3)points
.SetValue
(1,p1
)
points
.SetValue
(2,p2
)
points
.SetValue
(3,p3
)
approx
=Geom2dAPI_PointsToBSpline
(points
)display
, start_display
, add_menu
, add_function_to_menu
= init_display
()display
.DisplayShape
(approx
.Curve
(),update
=True)
display
.DisplayShape
(p1
)
display
.DisplayShape
(p2
)
display
.DisplayShape
(p3
)start_display
()
3d
from OCC
.Core
.GeomAPI
import GeomAPI_Interpolate
from OCC
.Core
.TColgp
import TColgp_HArray1OfPnt
from OCC
.Core
.gp
import gp_Pnt
from OCC
.Display
.SimpleGui
import init_displaypoints
=[]points
=TColgp_HArray1OfPnt
(1,3)
p1
=gp_Pnt
(0,1,2)
p2
=gp_Pnt
(2,1,3)
p3
=gp_Pnt
(6,2,1)points
.SetValue
(1,p1
)
points
.SetValue
(2,p2
)
points
.SetValue
(3,p3
)
interp
=GeomAPI_Interpolate
(points
,False,0.0001)
interp
.Perform
()display
, start_display
, add_menu
, add_function_to_menu
= init_display
()display
.DisplayShape
(interp
.Curve
(),update
=True)
display
.DisplayShape
(p1
)
display
.DisplayShape
(p2
)
display
.DisplayShape
(p3
)start_display
()
- 逼近法
GeomAPI類下的 GeomAPI_PointsToBSpline 可以允許建立3D BSpline曲線, 這用來逼近一系列的點。
from OCC
.Core
.GeomAPI
import GeomAPI_PointsToBSpline
from OCC
.Core
.TColgp
import TColgp_Array1OfPnt
from OCC
.Core
.gp
import gp_Pnt
from OCC
.Display
.SimpleGui
import init_displaypoints
=TColgp_Array1OfPnt
(1,3)
p1
=gp_Pnt
(0,1,2)
p2
=gp_Pnt
(2,1,3)
p3
=gp_Pnt
(6,2,1)points
.SetValue
(1,p1
)
points
.SetValue
(2,p2
)
points
.SetValue
(3,p3
)
approx
=GeomAPI_PointsToBSpline
(points
)display
, start_display
, add_menu
, add_function_to_menu
= init_display
()display
.DisplayShape
(approx
.Curve
(),update
=True)
display
.DisplayShape
(p1
)
display
.DisplayShape
(p2
)
display
.DisplayShape
(p3
)start_display
()
總結(jié)
以上是生活随笔為你收集整理的pythonocc进阶学习:曲线拟合(插值 Interpolation/逼近 Approximation)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。