使用Python-VTK绘制曲线

本文介绍如何使用VTK库在Python中创建三维曲线。通过定义点并使用vtkParametricSpline进行插值,最终渲染出彩色且加粗的三维曲线。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

import vtk

points = vtk.vtkPoints() # 定义一个点工具
points.InsertPoint(0, 329, 338, 45)  # 使用InsertPoint可以插入点
#注意:points.InsertPoint(a, b, c, d)
#其中a表示点的序号,(b,c,d)表示点的三维坐标
points.InsertPoint(1, 328, 319, 46)
points.InsertPoint(2, 300, 329, 96)
#定义曲线工具
#将前面的几个点插值拟合成一条曲线
spline = vtk.vtkParametricSpline()
spline.SetPoints(points)

splineSource = vtk.vtkParametricFunctionSource()
splineSource.SetParametricFunction(spline)
splineSource.Update()

splineMapper = vtk.vtkPolyDataMapper()
splineMapper.SetInputConnection(splineSource.GetOutputPort())

splineActor = vtk.vtkActor()
splineActor.SetMapper(splineMapper)
# 设置线条颜色
splineActor.GetProperty().SetColor(0.3800, 0.7000, 0.1600)
# 设置线条宽度
splineActor.GetProperty().SetLineWidth(5)


ren1 = vtk.vtkRenderer()
renWin = vtk.vtkRenderWindow()
renWin.AddRenderer(ren1)
iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)
ren1.AddActor(splineActor)

ren1.SetBackground(1, 1, 1)
renWin.SetSize(250, 250)
renWin.Render()
iren.Start()

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值