如何更改一个实例将更改NURBS-python / geomdl中的所有其他实例?

时间:2019-05-16 15:42:54

标签: python

以下代码将输出曲线图像,我希望crv1、2、3具有不同的形状或至少具有不同的控制点。

在查看最后一个图像输出时,看起来像通过更改crv3,crv 1和2一样,怎么可能呢?

from geomdl import BSpline
from geomdl import multi
from geomdl.visualization import VisMPL

crv1 = BSpline.Curve()
crv1.degree = 2
crv1.ctrlpts = [[1, 0], [1, 1], [0, 1]]
crv1.knotvector = [0, 0, 0, 1, 1, 1]
crv1.vis=VisMPL.VisCurve2D()
crv1.render()

crv2=crv1
crv2.insert_knot(0.25)
crv2.insert_knot(0.5)
crv2.insert_knot(0.75)
crv2.vis=VisMPL.VisCurve2D()
crv2.render()

crv3=crv2
crv3.remove_knot(0.5)
crv3.vis=VisMPL.VisCurve2D()
crv3.render()

crv=multi.CurveContainer([crv1, crv2, crv3])
crv.vis=VisMPL.VisCurve2D()
crv.render()

这是错误还是我的误解?请帮忙,多谢!

1 个答案:

答案 0 :(得分:0)

我认为使用deepcopy可以满足以下要求:

from copy import deepcopy
from geomdl import BSpline
from geomdl import multi
from geomdl.visualization import VisMPL

crv1 = BSpline.Curve()
crv1.degree = 2
crv1.ctrlpts = [[1, 0], [1, 1], [0, 1]]
crv1.knotvector = [0, 0, 0, 1, 1, 1]
crv1.vis=VisMPL.VisCurve2D()
crv1.render()

crv2=deepcopy(crv1)  # changed
crv2.insert_knot(0.25)
crv2.insert_knot(0.5)
crv2.insert_knot(0.75)
crv2.vis=VisMPL.VisCurve2D()
crv2.render()

crv3=deepcopy(crv2)  # changed
crv3.remove_knot(0.5)
crv3.vis=VisMPL.VisCurve2D()
crv3.render()

crv=multi.CurveContainer([crv1, crv2, crv3])
crv.vis=VisMPL.VisCurve2D()
crv.render()