回転#

Rotations of a mesh about its axes using rotate_x(), rotate_y(), and rotate_z(). In this model, the x axis is from the left to right; the y axis is from bottom to top; and the z axis emerges from the image. The camera location is the same in all four images.

from __future__ import annotations

import pyvista as pv
from pyvista import examples

カメラと軸を定義する#

カメラと軸を定義します.軸原点を (3.0, 3.0, 3.0) に設定します.

mesh = examples.download_cow()
mesh.points /= 1.5  # scale the mesh

camera = pv.Camera()
camera.position = (30.0, 30.0, 30.0)
camera.focal_point = (5.0, 5.0, 5.0)

axes = pv.Axes(show_actor=True, actor_scale=2.0, line_width=5)
axes.origin = (3.0, 3.0, 3.0)

元のメッシュ#

元のメッシュをプロットします.プロッタに軸アクターを追加します.

rotate

x軸を中心の回転.#

x軸を中心に60度ごとに回転したメッシュをプロットします.プロッタに軸アクターを追加し,軸の原点を回転点に設定します.

p = pv.Plotter()

p.add_text('X-Axis Rotation', font_size=24)
p.add_actor(axes.actor)
p.camera = camera

for i in range(6):
    rot = mesh.rotate_x(60 * i, point=axes.origin, inplace=False)
    p.add_mesh(rot)

p.show()
rotate

y軸を中心の回転.#

y軸を中心に60度ごとに回転したメッシュをプロットします.プロッタに軸アクターを追加し,軸の原点を回転点に設定します.

p = pv.Plotter()

p.add_text('Y-Axis Rotation', font_size=24)
p.camera = camera
p.add_actor(axes.actor)

for i in range(6):
    rot = mesh.rotate_y(60 * i, point=axes.origin, inplace=False)
    p.add_mesh(rot)

p.show()
rotate

z軸を中心の回転.#

z軸を中心に60度ごとに回転したメッシュをプロットします.プロッタに軸アクターを追加し,軸の原点を回転点に設定します.

p = pv.Plotter()

p.add_text('Z-Axis Rotation', font_size=24)
p.camera = camera
p.add_actor(axes.actor)

for i in range(6):
    rot = mesh.rotate_z(60 * i, point=axes.origin, inplace=False)
    p.add_mesh(rot)

p.show()
rotate

ベクトル中心の回転.#

カスタムベクトルを中心に60度ごとに回転させたメッシュをプロットします.プロッタに軸アクターを追加し,軸の原点を回転点に設定します.

p = pv.Plotter()

p.add_text('Custom Vector Rotation', font_size=24)
p.camera = camera
p.add_actor(axes.actor)
for i in range(6):
    rot = mesh.copy()
    rot.rotate_vector(vector=(1, 1, 1), angle=60 * i, point=axes.origin)
    p.add_mesh(rot)

p.show()
rotate

Tags: filter

Total running time of the script: (0 minutes 2.141 seconds)

Sphinx-Galleryによるギャラリー