RotationAroundLine 模型的旋转

一:主要的知识点

1、说明

本文只是教程内容的一小段,因博客字数限制,故进行拆分。主教程链接:vtk教程------逐行解析官网所有Python示例-CSDN博客

2、知识点纪要

本段代码主要涉及的有①模型的旋转

二:代码及注释

python 复制代码
import vtkmodules.vtkRenderingOpenGL2
import vtkmodules.vtkInteractionStyle
from vtkmodules.vtkFiltersSources import vtkArrowSource
from vtkmodules.vtkCommonColor import vtkNamedColors
from vtkmodules.vtkCommonTransforms import vtkTransform
from vtkmodules.vtkFiltersGeneral import vtkTransformPolyDataFilter
from vtkmodules.vtkRenderingCore import vtkActor, vtkPolyDataMapper, vtkRenderWindow, vtkRenderWindowInteractor, \
    vtkRenderer


def main():
    colors = vtkNamedColors()

    source = vtkArrowSource() # 原始方向(0,0,1)

    transform = vtkTransform()
    """
    RotateWXYZ  可自行定义所绕的轴以及绕的角度
    """
    transform.RotateWXYZ(45, 0, 0, 1)

    transformFilter = vtkTransformPolyDataFilter()
    transformFilter.SetInputConnection(source.GetOutputPort())
    transformFilter.SetTransform(transform)
    transformFilter.Update() # 旋转之后与X轴的夹角呈45°

    coneMapper1 = vtkPolyDataMapper()
    coneMapper1.SetInputConnection(source.GetOutputPort())

    actor1 = vtkActor()
    actor1.SetMapper(coneMapper1)

    coneMapper2 = vtkPolyDataMapper()
    coneMapper2.SetInputConnection(transformFilter.GetOutputPort())

    actor2 = vtkActor()
    actor2.SetMapper(coneMapper2)

    actor1.GetProperty().SetColor(colors.GetColor3d("LightCoral"))
    actor2.GetProperty().SetColor(colors.GetColor3d("PaleTurquoise"))

    render = vtkRenderer()
    render.AddActor(actor1)
    render.AddActor(actor2)
    render.SetBackground(colors.GetColor3d("SlateGray"))

    renWin = vtkRenderWindow()
    renWin.AddRenderer(render)
    renWin.SetSize(600, 480)
    renWin.SetWindowName("RotationAroundLine")

    iren = vtkRenderWindowInteractor()
    iren.SetRenderWindow(renWin)

    iren.Initialize()
    renWin.Render()
    iren.Start()



if __name__ == '__main__':
    main()
相关推荐
曲幽13 分钟前
FastAPI实战:打造本地文生图接口,ollama+diffusers让AI绘画更听话
python·fastapi·web·cors·diffusers·lcm·ollama·dreamshaper8·txt2img
老赵全栈实战41 分钟前
Pydantic配置管理最佳实践(一)
python
阿尔的代码屋6 小时前
[大模型实战 07] 基于 LlamaIndex ReAct 框架手搓全自动博客监控 Agent
人工智能·python
AI探索者1 天前
LangGraph StateGraph 实战:状态机聊天机器人构建指南
python
AI探索者1 天前
LangGraph 入门:构建带记忆功能的天气查询 Agent
python
FishCoderh1 天前
Python自动化办公实战:批量重命名文件,告别手动操作
python
躺平大鹅1 天前
Python函数入门详解(定义+调用+参数)
python
曲幽1 天前
我用FastAPI接ollama大模型,差点被asyncio整崩溃(附对话窗口实战)
python·fastapi·web·async·httpx·asyncio·ollama
两万五千个小时1 天前
落地实现 Anthropic Multi-Agent Research System
人工智能·python·架构
哈里谢顿1 天前
Python 高并发服务限流终极方案:从原理到生产落地(2026 实战指南)
python