File: extrude_rotate.py

package info (click to toggle)
python-pyvista 0.46.5-6
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 178,808 kB
  • sloc: python: 94,599; sh: 216; makefile: 70
file content (90 lines) | stat: -rw-r--r-- 2,278 bytes parent folder | download | duplicates (5)
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
"""
.. _extrude_rotate_example:

Extrude Rotation
~~~~~~~~~~~~~~~~
Sweep polygonal data creating "skirt" from free edges and lines, and
lines from vertices using the :meth:`~pyvista.PolyDataFilters.extrude_rotate`
filter.

This takes polygonal data as input and generates polygonal data on
output. The input dataset is swept around the z-axis to create
new polygonal primitives. These primitives form a "skirt" or
swept surface. For example, sweeping a line results in a
cylindrical shell, and sweeping a circle creates a torus.

"""

from __future__ import annotations

import numpy as np

import pyvista

# create a line and rotate it about the Z-axis
resolution = 10
line = pyvista.Line(pointa=(0, 0, 0), pointb=(1, 0, 0), resolution=2)
poly = line.extrude_rotate(resolution=resolution)
poly

# %%
# Plot the extruded line
# ~~~~~~~~~~~~~~~~~~~~~~


# sphinx_gallery_start_ignore
PYVISTA_GALLERY_FORCE_STATIC = True
# sphinx_gallery_end_ignore

plotter = pyvista.Plotter(shape=(2, 1))
plotter.subplot(0, 0)
plotter.add_text('Line', font_size=24)
plotter.add_mesh(line, color='lightblue', show_edges=True)
plotter.add_mesh(
    pyvista.PolyData(line.points),
    color='red',
    point_size=10,
    render_points_as_spheres=True,
)
plotter.subplot(1, 0)
plotter.add_text('Extrude Rotated Line', font_size=24)
plotter.add_mesh(poly, color='lightblue', show_edges=True)
plotter.add_mesh(
    pyvista.PolyData(poly.points),
    color='red',
    point_size=10,
    render_points_as_spheres=True,
)

plotter.show(cpos='xy')

# %%
# Create a spring
# ~~~~~~~~~~~~~~~

# Create the spring profile (a circle).
plotter = pyvista.Plotter()

vertices = np.array(
    [
        [1.0, 0.0, 0.0],
        [1.0732, 0.0, -0.1768],
        [1.25, 0.0, -0.25],
        [1.4268, 0.0, -0.1768],
        [1.5, 0.0, 0.00],
        [1.4268, 0.0, 0.1768],
        [1.25, 0.0, 0.25],
        [1.0732, 0.0, 0.1768],
    ],
)
faces = np.hstack([[8, 0, 1, 2, 3, 4, 5, 6, 7]])
profile = pyvista.PolyData(vertices, faces)

# Extrude the profile to make a spring.
spring = profile.extrude_rotate(resolution=360, translation=6.0, dradius=1.0, angle=2160.0)
plotter.add_text('Spring', font_size=24)
plotter.add_mesh(spring, color='lightblue', show_edges=True)

plotter.show(cpos='zx')
# %%
# .. tags:: filter