| 1 |
""" |
| 2 |
.. _extrude_rotate_example: |
| 3 |
|
| 4 |
Extrude Rotation |
| 5 |
~~~~~~~~~~~~~~~~ |
| 6 |
Sweep polygonal data creating "skirt" from free edges and lines, and |
| 7 |
lines from vertices using the :meth:`~pyvista.PolyDataFilters.extrude_rotate` |
| 8 |
filter. |
| 9 |
|
| 10 |
This takes polygonal data as input and generates polygonal data on |
| 11 |
output. The input dataset is swept around the z-axis to create |
| 12 |
new polygonal primitives. These primitives form a "skirt" or |
| 13 |
swept surface. For example, sweeping a line results in a |
| 14 |
cylindrical shell, and sweeping a circle creates a torus. |
| 15 |
|
| 16 |
""" |
| 17 |
|
| 18 |
import numpy as np |
| 19 |
import pyvista as pv |
| 20 |
|
| 21 |
# create a line and rotate it about the Z-axis |
| 22 |
resolution = 10 |
| 23 |
line = pv.Line(pointa=(0, 0, 0), pointb=(1, 0, 0), resolution=2) |
| 24 |
poly = line.extrude_rotate(resolution=resolution, capping=False) |
| 25 |
poly |
| 26 |
|
| 27 |
# %% |
| 28 |
# Plot the extruded line |
| 29 |
# ~~~~~~~~~~~~~~~~~~~~~~ |
| 30 |
|
| 31 |
|
| 32 |
# sphinx_gallery_start_ignore |
| 33 |
PYVISTA_GALLERY_FORCE_STATIC = True |
| 34 |
# sphinx_gallery_end_ignore |
| 35 |
|
| 36 |
pl = pv.Plotter(shape=(2, 1)) |
| 37 |
pl.subplot(0, 0) |
| 38 |
pl.add_text('Line', font_size=24) |
| 39 |
pl.add_mesh(line, color='lightblue', show_edges=True) |
| 40 |
pl.add_mesh( |
| 41 |
pv.PolyData(line.points), |
| 42 |
color='red', |
| 43 |
point_size=10, |
| 44 |
render_points_as_spheres=True, |
| 45 |
) |
| 46 |
pl.subplot(1, 0) |
| 47 |
pl.add_text('Extrude Rotated Line', font_size=24) |
| 48 |
pl.add_mesh(poly, color='lightblue', show_edges=True) |
| 49 |
pl.add_mesh( |
| 50 |
pv.PolyData(poly.points), |
| 51 |
color='red', |
| 52 |
point_size=10, |
| 53 |
render_points_as_spheres=True, |
| 54 |
) |
| 55 |
|
| 56 |
pl.show(cpos='xy') |
| 57 |
|
| 58 |
# %% |
| 59 |
# Create a spring |
| 60 |
# ~~~~~~~~~~~~~~~ |
| 61 |
|
| 62 |
# Create the spring profile (a circle). |
| 63 |
pl = pv.Plotter() |
| 64 |
|
| 65 |
vertices = np.array( |
| 66 |
[ |
| 67 |
[1.0, 0.0, 0.0], |
| 68 |
[1.0732, 0.0, -0.1768], |
| 69 |
[1.25, 0.0, -0.25], |
| 70 |
[1.4268, 0.0, -0.1768], |
| 71 |
[1.5, 0.0, 0.00], |
| 72 |
[1.4268, 0.0, 0.1768], |
| 73 |
[1.25, 0.0, 0.25], |
| 74 |
[1.0732, 0.0, 0.1768], |
| 75 |
], |
| 76 |
) |
| 77 |
faces = np.hstack([[8, 0, 1, 2, 3, 4, 5, 6, 7]]) |
| 78 |
profile = pv.PolyData(vertices, faces) |
| 79 |
|
| 80 |
# Extrude the profile to make a spring. |
| 81 |
spring = profile.extrude_rotate( |
| 82 |
resolution=360, translation=6.0, dradius=1.0, angle=2160.0, capping=False |
| 83 |
) |
| 84 |
pl.add_text('Spring', font_size=24) |
| 85 |
pl.add_mesh(spring, color='lightblue', show_edges=True) |
| 86 |
|
| 87 |
pl.show(cpos='zx') |
| 88 |
# %% |
| 89 |
# .. tags:: filter |