Skip to content
Projects

Cylinder

Download notebookView on GitHubRun when the site was built.

A solid circular cylinder along any axis: rods, posts and feedthroughs.

Cylinder(start, end, radius) runs from the centre of one end face to the other; fillet rounds the two circular edges. The level set is the exact signed distance, that of the profile in the half-plane of axial position and radius.

import numpy as np
from simgeometry import Cylinder
rod = Cylinder(start=(0.0, 0.0, 0.0), end=(2.0, 0.0, 1.0), radius=0.3, fillet=0.1)
print("length:", rod.length, " volume:", round(rod.volume(), 4))
print("on the axis:", rod.contains((1.0, 0.0, 0.5)))
side = (1.0, 1.0, 0.5) # 1 from the middle of the axis, normal to it
print("distance from", np.round(side, 3), ":", rod.signed_distance(side))
assert np.isclose(rod.length, np.sqrt(5))
assert np.isclose(rod.signed_distance(side), 0.7)
length: 2.23606797749979 volume: 0.6247
on the axis: True
distance from [1. 1. 0.5] : 0.7000000000000001
import plasma_plots
import pyvista as pv
pv.OFF_SCREEN = True # render without a window, e.g. on a docs server
plotter = rod.show_3d(
backend="pyvista", display=False, resolution=64, show_bounds=False
)
plasma_plots.scene(plotter, alt="A tilted cylinder with rounded edges")
A tilted cylinder with rounded edges
Open in a new tab