Debian Codegraph @

examples/01-filter/rotate.py

raw
1 """
2 .. _rotate_example:
3
4 Rotations
5 ~~~~~~~~~
6
7 Rotations of a mesh about its axes using
8 :meth:`~pyvista.DataObjectFilters.rotate_x`,
9 :meth:`~pyvista.DataObjectFilters.rotate_y`, and
10 :meth:`~pyvista.DataObjectFilters.rotate_z`.
11 In this model, the x axis is from the left to right;
12 the y axis is from bottom to top; and the z axis emerges from the
13 image. The camera location is the same in all four images.
14
15 """
16
17 # sphinx_gallery_thumbnail_number = 3
18 import pyvista as pv
19 from pyvista import examples
20
21 # %%
22 # Define camera position and axes
23 # +++++++++++++++++++++++++++++++
24 #
25 # Define camera position and axes. Setting axes origin to ``(3.0, 3.0, 3.0)``.
26
27 mesh = examples.download_cow()
28 mesh.points /= 1.5 # scale the mesh
29
30 cpos = [
31 (30.0, 30.0, 30.0), # position
32 (5.0, 5.0, 5.0), # focal point
33 (0.0, 1.0, 0.0), # view up
34 ]
35
36
37 axes = pv.Axes(show_actor=True, actor_scale=2.0, line_width=5)
38 axes.origin = (3.0, 3.0, 3.0)
39
40 # %%
41 # Original Mesh
42 # +++++++++++++
43 #
44 # Plot original mesh. Add axes actor to Plotter.
45
46 pl = pv.Plotter()
47
48 pl.add_text('Mesh', font_size=24)
49 pl.add_actor(axes.actor)
50 pl.add_mesh(mesh)
51
52 pl.show(cpos=cpos)
53
54 # %%
55 # Rotation about the x axis
56 # +++++++++++++++++++++++++
57 #
58 # Plot the mesh rotated about the x axis every 60 degrees.
59 # Add the axes actor to the Plotter and set the axes origin to the point of rotation.
60
61 pl = pv.Plotter()
62
63 pl.add_text('X-Axis Rotation', font_size=24)
64 pl.add_actor(axes.actor)
65
66 for i in range(6):
67 rot = mesh.rotate_x(60 * i, point=axes.origin, inplace=False)
68 pl.add_mesh(rot)
69
70 pl.show(cpos=cpos)
71
72 # %%
73 # Rotation about the y axis
74 # +++++++++++++++++++++++++
75 #
76 # Plot the mesh rotated about the y axis every 60 degrees.
77 # Add the axes actor to the Plotter and set the axes origin to the point of rotation.
78
79 pl = pv.Plotter()
80
81 pl.add_text('Y-Axis Rotation', font_size=24)
82 pl.add_actor(axes.actor)
83
84 for i in range(6):
85 rot = mesh.rotate_y(60 * i, point=axes.origin, inplace=False)
86 pl.add_mesh(rot)
87
88 pl.show(cpos=cpos)
89
90 # %%
91 # Rotation about the z axis
92 # +++++++++++++++++++++++++
93 #
94 # Plot the mesh rotated about the z axis every 60 degrees.
95 # Add axes actor to the Plotter and set the axes origin to the point of rotation.
96
97 pl = pv.Plotter()
98
99 pl.add_text('Z-Axis Rotation', font_size=24)
100 pl.add_actor(axes.actor)
101
102 for i in range(6):
103 rot = mesh.rotate_z(60 * i, point=axes.origin, inplace=False)
104 pl.add_mesh(rot)
105
106 pl.show(cpos=cpos)
107
108 # %%
109 # Rotation about a custom vector
110 # ++++++++++++++++++++++++++++++
111 #
112 # Plot the mesh rotated about a custom vector every 60 degrees.
113 # Add the axes actor to the Plotter and set axes origin to the point of rotation.
114
115 pl = pv.Plotter()
116
117 pl.add_text('Custom Vector Rotation', font_size=24)
118 pl.add_actor(axes.actor)
119 for i in range(6):
120 rot = mesh.copy()
121 rot.rotate_vector(vector=(1, 1, 1), angle=60 * i, point=axes.origin)
122 pl.add_mesh(rot)
123
124 pl.show(cpos=cpos)
125 # %%
126 # .. tags:: filter