File: rotate.py

package info (click to toggle)
python-pyvista 0.46.4-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 176,968 kB
  • sloc: python: 94,346; sh: 216; makefile: 70
file content (130 lines) | stat: -rw-r--r-- 2,917 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
"""
.. _rotate_example:

Rotations
~~~~~~~~~

Rotations of a mesh about its axes using
:meth:`~pyvista.DataObjectFilters.rotate_x`,
:meth:`~pyvista.DataObjectFilters.rotate_y`, and
:meth:`~pyvista.DataObjectFilters.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.

"""

# sphinx_gallery_thumbnail_number = 3
from __future__ import annotations

import pyvista as pv
from pyvista import examples

# %%
# Define camera and axes
# ++++++++++++++++++++++
#
# Define camera and axes. Setting axes origin to ``(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)

# %%
# Original Mesh
# +++++++++++++
#
# Plot original mesh. Add axes actor to Plotter.

p = pv.Plotter()

p.add_text('Mesh', font_size=24)
p.add_actor(axes.actor)
p.camera = camera
p.add_mesh(mesh)

p.show()

# %%
# Rotation about the x axis
# +++++++++++++++++++++++++
#
# Plot the mesh rotated about the x axis every 60 degrees.
# Add the axes actor to the Plotter and set the axes origin to the point of rotation.

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()

# %%
# Rotation about the y axis
# +++++++++++++++++++++++++
#
# Plot the mesh rotated about the y axis every 60 degrees.
# Add the axes actor to the Plotter and set the axes origin to the point of rotation.

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()

# %%
# Rotation about the z axis
# +++++++++++++++++++++++++
#
# Plot the mesh rotated about the z axis every 60 degrees.
# Add axes actor to the Plotter and set the axes origin to the point of rotation.

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()

# %%
# Rotation about a custom vector
# ++++++++++++++++++++++++++++++
#
# Plot the mesh rotated about a custom vector every 60 degrees.
# Add the axes actor to the Plotter and set axes origin to the point of rotation.

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()
# %%
# .. tags:: filter