Primitives#
physicsnemo.mesh.primitives is a catalog of ready-made meshes for
tutorials, tests, and experiments. The library builds each mesh when you ask
for it, except the PyVista datasets, which it downloads. Each primitive is a
module with one load function. Its keyword arguments set the size and the
resolution, and device sets where the tensors go. The text module is
the exception, with one function for each kind of text mesh.
CPU and GPU points to volumes deterministic
Fig. 36 Two primitives from each family, labeled with the module path and with the manifold and spatial dimensions. The volume meshes are cut open, and the faces of the tetrahedra on each cut are drawn in a lighter tint.#
The most-used primitives are the following:
A closed surface with near-equilateral triangles.
A 2D domain for quick tests of fields and calculus.
A tetrahedral ball.
Example#
from physicsnemo.mesh.primitives import curves, planar, procedural, surfaces, volumes
sphere = surfaces.sphere_icosahedral.load(radius=1.0, subdivisions=2)
print(sphere)
# Mesh[n_manifold_dims=2, n_spatial_dims=3](n_points=162, n_cells=320)
helix = curves.helix_3d.load(n_turns=2.0) # edges in 3D
ball = volumes.sphere_volume.load(resolution=10) # tetrahedra in 3D
# Procedural meshes perturb a mesh with a fixed seed.
square = planar.unit_square.load(subdivisions=3)
noisy = procedural.noisy_mesh.load(square, noise_scale=0.01, seed=0)
To make a mesh on a GPU, pass device="cuda" to load.
Catalog#
The tables give each primitive’s type as
Mesh[n_manifold_dims, n_spatial_dims]. For example, Mesh[2, 3] is a
triangle mesh in 3D space. Each name links to the reference of its load
function, which lists the arguments and defaults.
physicsnemo.mesh.primitives.curves: One-dimensional meshes (edges) in 1D, 2D, or 3D space, including lines, arcs, closed curves, a helix, and a knot. The following table lists its primitives:
Module |
Type |
Description |
|---|---|---|
|
A closed circle curve in 2D space |
|
|
A closed circle curve in 3D space |
|
|
A circular arc in 2D space |
|
|
A closed ellipse curve in 2D space |
|
|
A helical curve in 3D space |
|
|
A line segment in 1D space |
|
|
Multiple disconnected line segments in 1D space |
|
|
A zigzag polyline in 2D space |
|
|
An Archimedean spiral in 2D space |
|
|
A 3D spiral curve |
|
|
A straight line segment in 2D space |
|
|
A straight line segment in 3D space |
|
|
A trefoil knot curve in 3D space |
physicsnemo.mesh.primitives.planar: Triangle meshes that fill a region of the plane, including squares, rectangles, disks, an annulus, polygons, and a non-convex L shape. The following table lists its primitives:
Module |
Type |
Description |
|---|---|---|
|
An annulus (ring) triangulated in 2D space |
|
|
A filled disk (circle) triangulated in 2D space |
|
|
An equilateral triangle in 2D space |
|
|
An L-shaped non-convex domain in 2D space |
|
|
A triangulated rectangle in 2D space |
|
|
A regular polygon triangulated in 2D space |
|
|
A structured triangular grid in 2D space |
|
|
A triangulated unit square in 2D space |
physicsnemo.mesh.primitives.surfaces: Triangle meshes in 3D space. The closed surfaces are spheres, a torus, Platonic solids, a cylinder with caps, and a cone. The open ones are a plane, a disk, a hemisphere, an open cylinder, and a Möbius strip. The following table lists its primitives:
Module |
Type |
Description |
|---|---|---|
|
A cone surface in 3D space |
|
|
A cube surface triangulated in 3D space |
|
|
A cylinder surface (with caps) in 3D space |
|
|
An open cylinder surface (without caps) in 3D space |
|
|
A flat disk in 3D space (in the xy-plane) |
|
|
A hemisphere surface in 3D space |
|
|
A regular icosahedron surface in 3D space |
|
|
A Möbius strip surface in 3D space |
|
|
A regular octahedron surface in 3D space |
|
|
A flat triangulated plane in 3D space |
|
|
A subdivided icosahedron projected onto a sphere |
|
|
A UV sphere using latitude and longitude parameterization |
|
|
A regular tetrahedron surface in 3D space |
|
|
A torus surface in 3D space |
physicsnemo.mesh.primitives.volumes: Tetrahedral meshes that fill a solid in 3D space. The following table lists its primitives:
Module |
Type |
Description |
|---|---|---|
|
A tetrahedral volume mesh of a cube |
|
|
A tetrahedral volume mesh of a cylinder |
|
|
A tetrahedral volume mesh of a sphere |
|
|
A single regular tetrahedron volume |
physicsnemo.mesh.primitives.procedural: Meshes with seeded random perturbations, for tests that need irregular geometry. Each load function takes a seed argument. The helper module procedural.noise provides the Perlin noise functions that they use: perlin_noise_1d, perlin_noise_2d, perlin_noise_3d, and perlin_noise_nd. The following table lists its primitives:
Module |
Type |
Description |
|---|---|---|
|
A lumpy ball volume mesh |
|
|
A sphere with radial noise |
|
same as input |
A copy of |
|
|
A perturbed structured grid in 2D space |
physicsnemo.mesh.primitives.basic: Meshes with one to three cells, for unit tests and small examples. The following table lists its primitives:
Module |
Type |
Description |
|---|---|---|
|
A mesh with a single edge in 2D space |
|
|
A mesh with a single edge in 3D space |
|
|
A mesh with a single point in 2D space |
|
|
A mesh with a single point in 3D space |
|
|
A mesh with a single tetrahedron in 3D space |
|
|
A mesh with a single triangle in 2D space |
|
|
A mesh with a single triangle in 3D space |
|
|
A polyline with three edges in 2D space |
|
|
A polyline with three edges in 3D space |
|
|
A mesh with three points in 2D space |
|
|
A mesh with three points in 3D space |
|
|
A mesh with two tetrahedra in 3D space |
|
|
A mesh with two triangles in 2D space |
|
|
A mesh with two triangles in 3D space |
physicsnemo.mesh.primitives.pyvista_datasets: Example datasets from PyVista, converted to a Mesh. These need pyvista, and the first call downloads the file. Conversion splits cells other than simplices into simplices. The following table lists its primitives:
Module |
Type |
Description |
|---|---|---|
|
Airplane surface mesh from PyVista examples |
|
|
Ant surface mesh from PyVista examples |
|
|
Stanford bunny surface mesh from PyVista examples |
|
|
Cow surface mesh from PyVista examples |
|
|
Globe surface mesh from PyVista examples |
|
|
Hexahedral beam from PyVista examples, split into tetrahedra |
|
|
Tetrahedral beam volume mesh from PyVista examples |
physicsnemo.mesh.primitives.text: Meshes of a text string, built from the
outlines of a bold sans-serif font through matplotlib. These need
matplotlib. Each function
takes the string, a font size, and the sampling resolution of the outlines. The
following table lists its functions:
Function |
Type |
Description |
|---|---|---|
|
Letter outlines as closed curves in the plane |
|
|
Filled, triangulated letters in the plane |
|
|
Surface of the extruded letters in 3D |
|
|
Solid extruded letters, as tetrahedra |
Choosing a Primitive#
Use the following guidelines to choose a primitive:
For a quick closed surface, use
surfaces.sphere_icosahedral. Its triangles are close to equilateral, so it suits calculus and curvature checks.surfaces.sphere_uvhas small, thin triangles near its poles.For a surface with a boundary, use
surfaces.plane,surfaces.disk,surfaces.hemisphere, orsurfaces.cylinder_open.For a 2D simulation domain, use
planar.unit_square,planar.rectangle, orplanar.structured_grid.planar.l_shapehas a re-entrant corner, andplanar.annulus_2dhas a hole.For a unit test that needs exact values, use a mesh from
basic.For a mesh of your own geometry, refer to Generate, Tessellation, and I/O.
API Reference#
Curves#
- physicsnemo.mesh.primitives.curves.circle_2d.load(
- radius: float = 1.0,
- n_points: int = 32,
- device: device | str = 'cpu',
Create a closed circle curve in 2D space.
The points run counterclockwise, so the edge normals point inward, as described in Orientation Conventions.
- Parameters:
radius (float) – Radius of the circle.
n_points (int) – Number of points around the circle.
device (str) – Compute device (‘cpu’ or ‘cuda’).
- Returns:
Mesh with n_manifold_dims=1, n_spatial_dims=2, n_cells=n_points.
- Return type:
Mesh[1, 2]
- physicsnemo.mesh.primitives.curves.circle_3d.load(
- radius: float = 1.0,
- center: tuple[float, float, float] = (0.0, 0.0, 0.0),
- normal: tuple[float, float, float] = (0.0, 0.0, 1.0),
- n_points: int = 32,
- device: device | str = 'cpu',
Create a closed circle curve in 3D space.
- Parameters:
radius (float) – Radius of the circle.
center (tuple[float, float, float]) – Center point (x, y, z).
normal (tuple[float, float, float]) – Normal vector to the circle plane (will be normalized).
n_points (int) – Number of points around the circle.
device (str) – Compute device (‘cpu’ or ‘cuda’).
- Returns:
Mesh with n_manifold_dims=1, n_spatial_dims=3, n_cells=n_points.
- Return type:
Mesh[1, 3]
- physicsnemo.mesh.primitives.curves.circular_arc_2d.load(
- radius: float = 1.0,
- start_angle: float = 0.0,
- end_angle: float = 1.5707963267948966,
- n_points: int = 20,
- device: device | str = 'cpu',
Create a circular arc in 2D space.
- Parameters:
radius (float) – Radius of the arc.
start_angle (float) – Starting angle in radians.
end_angle (float) – Ending angle in radians.
n_points (int) – Number of points along the arc.
device (str) – Compute device (‘cpu’ or ‘cuda’).
- Returns:
Mesh with n_manifold_dims=1, n_spatial_dims=2, n_cells=n_points-1.
- Return type:
Mesh[1, 2]
- physicsnemo.mesh.primitives.curves.ellipse_2d.load(
- semi_major_axis: float = 2.0,
- semi_minor_axis: float = 1.0,
- n_points: int = 48,
- device: device | str = 'cpu',
Create a closed ellipse curve in 2D space.
The points run counterclockwise, so the edge normals point inward, as described in Orientation Conventions.
- Parameters:
semi_major_axis (float) – Length of semi-major axis (x-direction).
semi_minor_axis (float) – Length of semi-minor axis (y-direction).
n_points (int) – Number of points around the ellipse.
device (str) – Compute device (‘cpu’ or ‘cuda’).
- Returns:
Mesh with n_manifold_dims=1, n_spatial_dims=2, n_cells=n_points.
- Return type:
Mesh[1, 2]
- physicsnemo.mesh.primitives.curves.helix_3d.load(
- radius: float = 1.0,
- height: float = 5.0,
- n_turns: float = 3.0,
- n_points: int = 100,
- device: device | str = 'cpu',
Create a helical curve in 3D space.
- Parameters:
radius (float) – Radius of the helix.
height (float) – Total height of the helix.
n_turns (float) – Number of complete turns.
n_points (int) – Number of points along the helix.
device (str) – Compute device (‘cpu’ or ‘cuda’).
- Returns:
Mesh with n_manifold_dims=1, n_spatial_dims=3, n_cells=n_points-1.
- Return type:
Mesh[1, 3]
- physicsnemo.mesh.primitives.curves.line_segment_1d.load(
- length: float = 1.0,
- n_points: int = 2,
- device: device | str = 'cpu',
Create a line segment in 1D space.
- Parameters:
length (float) – Length of the line segment.
n_points (int) – Number of points (minimum 2).
device (str) – Compute device (‘cpu’ or ‘cuda’).
- Returns:
Mesh with n_manifold_dims=1, n_spatial_dims=1, n_cells=n_points-1.
- Return type:
Mesh[1, 1]
- physicsnemo.mesh.primitives.curves.line_segments_1d.load(
- n_segments: int = 3,
- gap: float = 0.2,
- device: device | str = 'cpu',
Create multiple disconnected line segments in 1D space.
- Parameters:
n_segments (int) – Number of disconnected segments.
gap (float) – Gap between segments.
device (str) – Compute device (‘cpu’ or ‘cuda’).
- Returns:
Mesh with n_manifold_dims=1, n_spatial_dims=1, n_cells=n_segments.
- Return type:
Mesh[1, 1]
- physicsnemo.mesh.primitives.curves.polyline_2d.load(
- n_segments: int = 10,
- amplitude: float = 0.5,
- wavelength: float = 1.0,
- device: device | str = 'cpu',
Create a zigzag polyline in 2D space.
- Parameters:
n_segments (int) – Number of segments in the polyline.
amplitude (float) – Amplitude of the zigzag. Vertices alternate between
y = -amplitudeandy = +amplitude.wavelength (float) – Horizontal spacing between consecutive vertices (the length of one segment along x). The zigzag repeats every two segments, so its period is
2 * wavelength.device (str) – Compute device (‘cpu’ or ‘cuda’).
- Returns:
Mesh with n_manifold_dims=1, n_spatial_dims=2, n_cells=n_segments.
- Return type:
Mesh[1, 2]
- physicsnemo.mesh.primitives.curves.spiral_2d.load(
- n_turns: float = 3.0,
- spacing: float = 0.5,
- n_points: int = 100,
- device: device | str = 'cpu',
Create an Archimedean spiral in 2D space.
The spiral follows r = spacing * theta.
- Parameters:
n_turns (float) – Number of complete turns.
spacing (float) – Radial growth per radian of turn, so successive turns are
2 * pi * spacingapart.n_points (int) – Number of points along the spiral.
device (str) – Compute device (‘cpu’ or ‘cuda’).
- Returns:
Mesh with n_manifold_dims=1, n_spatial_dims=2, n_cells=n_points-1.
- Return type:
Mesh[1, 2]
- physicsnemo.mesh.primitives.curves.spline_3d.load(
- n_points: int = 1000,
- device: device | str = 'cpu',
Create a 3D spiral curve.
The curve is a parametric spiral where the radius varies with z-coordinate, creating a helix that widens at the ends. This is the same curve as PyVista’s
pv.examples.load_spline().- Parameters:
n_points (int) – Number of points along the curve (default: 1000, matching PyVista).
device (torch.device or str) – Compute device (‘cpu’ or ‘cuda’).
- Returns:
Mesh with n_manifold_dims=1, n_spatial_dims=3, n_cells=n_points-1.
- Return type:
Mesh[1, 3]
Examples
>>> from physicsnemo.mesh.primitives.curves import spline_3d >>> mesh = spline_3d.load() >>> mesh.n_points, mesh.n_cells (1000, 999) >>> mesh.n_spatial_dims, mesh.n_manifold_dims (3, 1)
- physicsnemo.mesh.primitives.curves.straight_line_2d.load(
- start: tuple[float, float] = (0.0, 0.0),
- end: tuple[float, float] = (1.0, 1.0),
- n_points: int = 10,
- device: device | str = 'cpu',
Create a straight line segment in 2D space.
- Parameters:
start (tuple[float, float]) – Starting point (x, y).
end (tuple[float, float]) – Ending point (x, y).
n_points (int) – Number of points along the line.
device (str) – Compute device (‘cpu’ or ‘cuda’).
- Returns:
Mesh with n_manifold_dims=1, n_spatial_dims=2, n_cells=n_points-1.
- Return type:
Mesh[1, 2]
- physicsnemo.mesh.primitives.curves.straight_line_3d.load(
- start: tuple[float, float, float] = (0.0, 0.0, 0.0),
- end: tuple[float, float, float] = (1.0, 1.0, 1.0),
- n_points: int = 10,
- device: device | str = 'cpu',
Create a straight line segment in 3D space.
- Parameters:
start (tuple[float, float, float]) – Starting point (x, y, z).
end (tuple[float, float, float]) – Ending point (x, y, z).
n_points (int) – Number of points along the line.
device (str) – Compute device (‘cpu’ or ‘cuda’).
- Returns:
Mesh with n_manifold_dims=1, n_spatial_dims=3, n_cells=n_points-1.
- Return type:
Mesh[1, 3]
- physicsnemo.mesh.primitives.curves.trefoil_knot_3d.load(
- scale: float = 1.0,
- n_points: int = 100,
- device: device | str = 'cpu',
Create a trefoil knot curve in 3D space.
The trefoil knot is the simplest nontrivial knot. Its parametric equations are:
x = sin(t) + 2*sin(2*t) y = cos(t) - 2*cos(2*t) z = -sin(3*t)
- Parameters:
scale (float) – Overall scale factor.
n_points (int) – Number of points around the knot.
device (str) – Compute device (‘cpu’ or ‘cuda’).
- Returns:
Mesh with n_manifold_dims=1, n_spatial_dims=3, n_cells=n_points.
- Return type:
Mesh[1, 3]
Planar Meshes#
- physicsnemo.mesh.primitives.planar.annulus_2d.load(
- inner_radius: float = 0.5,
- outer_radius: float = 1.0,
- n_radial: int = 5,
- n_angular: int = 32,
- device: device | str = 'cpu',
Create an annulus (ring) triangulated in 2D space.
- Parameters:
inner_radius (float) – Inner radius of the annulus.
outer_radius (float) – Outer radius of the annulus.
n_radial (int) – Number of points in radial direction.
n_angular (int) – Number of points around the circumference.
device (torch.device or str) – Compute device (‘cpu’ or ‘cuda’).
- Returns:
Mesh with n_manifold_dims=2, n_spatial_dims=2.
- Return type:
Mesh[2, 2]
Examples
>>> from physicsnemo.mesh.primitives.planar import annulus_2d >>> mesh = annulus_2d.load() >>> mesh.n_manifold_dims, mesh.n_spatial_dims (2, 2)
- physicsnemo.mesh.primitives.planar.circle_2d.load(
- radius: float = 1.0,
- n_radial: int = 10,
- n_angular: int = 32,
- device: device | str = 'cpu',
Create a filled disk (circle) triangulated in 2D space.
The disk is meshed with a center point connected by a triangle fan to the innermost ring, and concentric rings connected by quads (split into triangles).
- Parameters:
radius (float) – Radius of the disk.
n_radial (int) – Number of rings (including center point as ring 0).
n_angular (int) – Number of points around the circumference.
device (torch.device or str) – Compute device (‘cpu’ or ‘cuda’).
- Returns:
Mesh with n_manifold_dims=2, n_spatial_dims=2.
- Return type:
Mesh[2, 2]
Examples
>>> from physicsnemo.mesh.primitives.planar import circle_2d >>> mesh = circle_2d.load() >>> mesh.n_manifold_dims, mesh.n_spatial_dims (2, 2)
- physicsnemo.mesh.primitives.planar.equilateral_triangle.load(
- side_length: float = 1.0,
- subdivisions: int = 0,
- device: device | str = 'cpu',
Create an equilateral triangle in 2D space.
- Parameters:
side_length (float) – Length of each side.
subdivisions (int) – Number of subdivision levels. Each level quadruples the number of triangles: 0 → 1, 1 → 4, 2 → 16, etc.
device (str) – Compute device (‘cpu’ or ‘cuda’).
- Returns:
Mesh with n_manifold_dims=2, n_spatial_dims=2.
- Return type:
Mesh[2, 2]
- physicsnemo.mesh.primitives.planar.l_shape.load(
- size: float = 1.0,
- subdivisions: int = 5,
- device: device | str = 'cpu',
Create an L-shaped non-convex domain in 2D space.
The L-shape consists of:
Bottom rectangle: [0, size] x [0, size/2]
Top rectangle: [0, size/2] x [size/2, size]
Both parts use uniform grid spacing of size/(2*subdivisions), and the vertices at y=size/2 for x in [0, size/2] are shared between the parts.
Every triangle is wound counterclockwise, with a positive signed area, as described in Orientation Conventions.
- Parameters:
size (float) – Size of the L-shape (both overall width and height).
subdivisions (int) – Number of subdivisions per half-edge (so the full width has 2*subdivisions cells).
device (str) – Compute device (‘cpu’ or ‘cuda’).
- Returns:
Mesh with n_manifold_dims=2, n_spatial_dims=2.
- Return type:
Mesh[2, 2]
- physicsnemo.mesh.primitives.planar.rectangle.load(
- width: float = 2.0,
- height: float = 1.0,
- n_x: int = 10,
- n_y: int = 5,
- device: device | str = 'cpu',
Create a triangulated rectangle in 2D space.
Every triangle is wound counterclockwise, with a positive signed area, as described in Orientation Conventions.
- Parameters:
width (float) – Width of the rectangle.
height (float) – Height of the rectangle.
n_x (int) – Number of points in x-direction.
n_y (int) – Number of points in y-direction.
device (str) – Compute device (‘cpu’ or ‘cuda’).
- Returns:
Mesh with n_manifold_dims=2, n_spatial_dims=2.
- Return type:
Mesh[2, 2]
- physicsnemo.mesh.primitives.planar.regular_polygon.load(
- n_sides: int = 6,
- radius: float = 1.0,
- device: device | str = 'cpu',
Create a regular polygon triangulated in 2D space.
The polygon is triangulated by connecting all vertices to the center point.
- Parameters:
n_sides (int) – Number of sides (must be >= 3).
radius (float) – Distance from center to vertices.
device (str) – Compute device (‘cpu’ or ‘cuda’).
- Returns:
Mesh with n_manifold_dims=2, n_spatial_dims=2.
- Return type:
Mesh[2, 2]
- physicsnemo.mesh.primitives.planar.structured_grid.load(
- x_min: float = 0.0,
- x_max: float = 1.0,
- y_min: float = 0.0,
- y_max: float = 1.0,
- n_x: int = 11,
- n_y: int = 11,
- device: device | str = 'cpu',
Create a structured triangular grid in 2D space.
Every triangle is wound counterclockwise, with a positive signed area, as described in Orientation Conventions.
- Parameters:
x_min (float) – Minimum x coordinate.
x_max (float) – Maximum x coordinate.
y_min (float) – Minimum y coordinate.
y_max (float) – Maximum y coordinate.
n_x (int) – Number of points in x-direction.
n_y (int) – Number of points in y-direction.
device (str) – Compute device (‘cpu’ or ‘cuda’).
- Returns:
Mesh with n_manifold_dims=2, n_spatial_dims=2.
- Return type:
Mesh[2, 2]
- physicsnemo.mesh.primitives.planar.unit_square.load(
- subdivisions: int = 1,
- device: device | str = 'cpu',
Create a triangulated unit square in 2D space.
Every triangle is wound counterclockwise, with a positive signed area, as described in Orientation Conventions.
- Parameters:
subdivisions (int) – Number of subdivision levels (0 = 2 triangles). Each level quadruples the number of triangles: 0 → 2, 1 → 8, 2 → 32, etc.
device (str) – Compute device (‘cpu’ or ‘cuda’).
- Returns:
Mesh with n_manifold_dims=2, n_spatial_dims=2.
- Return type:
Mesh[2, 2]
Surfaces#
- physicsnemo.mesh.primitives.surfaces.cone.load(
- radius: float = 1.0,
- height: float = 2.0,
- n_circ: int = 32,
- n_height: int = 10,
- device: device | str = 'cpu',
Create a cone surface in 3D space.
- Parameters:
radius (float) – Radius of the base.
height (float) – Height of the cone.
n_circ (int) – Number of points around the base circumference.
n_height (int) – Number of points along the height.
device (str) – Compute device (‘cpu’ or ‘cuda’).
- Returns:
Mesh with n_manifold_dims=2, n_spatial_dims=3.
- Return type:
Mesh[2, 3]
- physicsnemo.mesh.primitives.surfaces.cube_surface.load(
- size: float = 1.0,
- device: device | str = 'cpu',
Create a cube surface triangulated in 3D space.
The cube is centered at the origin with vertices at (±size/2, ±size/2, ±size/2). Each face is split into 2 triangles with consistent outward-facing normals (counter-clockwise winding when viewed from outside).
- Parameters:
size (float) – Side length of the cube.
device (torch.device or str) – Compute device (‘cpu’ or ‘cuda’).
- Returns:
Mesh with n_manifold_dims=2, n_spatial_dims=3, 8 vertices, 12 triangles.
- Return type:
Mesh[2, 3]
Examples
>>> from physicsnemo.mesh.primitives.surfaces import cube_surface >>> mesh = cube_surface.load() >>> mesh.n_points, mesh.n_cells (8, 12) >>> mesh.n_manifold_dims, mesh.n_spatial_dims (2, 3)
- physicsnemo.mesh.primitives.surfaces.cylinder.load(
- radius: float = 1.0,
- height: float = 2.0,
- n_circ: int = 32,
- n_height: int = 10,
- device: device | str = 'cpu',
Create a cylinder surface (with caps) in 3D space.
- Parameters:
radius (float) – Radius of the cylinder.
height (float) – Height of the cylinder.
n_circ (int) – Number of points around the circumference.
n_height (int) – Number of points along the height.
device (str) – Compute device (‘cpu’ or ‘cuda’).
- Returns:
Mesh with n_manifold_dims=2, n_spatial_dims=3.
- Return type:
Mesh[2, 3]
- physicsnemo.mesh.primitives.surfaces.cylinder_open.load(
- radius: float = 1.0,
- height: float = 2.0,
- n_circ: int = 32,
- n_height: int = 10,
- device: device | str = 'cpu',
Create an open cylinder surface (without caps) in 3D space.
- Parameters:
radius (float) – Radius of the cylinder.
height (float) – Height of the cylinder.
n_circ (int) – Number of points around the circumference.
n_height (int) – Number of points along the height.
device (str) – Compute device (‘cpu’ or ‘cuda’).
- Returns:
Mesh with n_manifold_dims=2, n_spatial_dims=3, has boundary edges.
- Return type:
Mesh[2, 3]
- physicsnemo.mesh.primitives.surfaces.disk.load(
- radius: float = 1.0,
- n_radial: int = 10,
- n_angular: int = 32,
- device: device | str = 'cpu',
Create a flat disk in 3D space (lying in xy-plane).
The triangles are wound counterclockwise, so the normals point in the +z direction, as described in Orientation Conventions.
- Parameters:
radius (float) – Radius of the disk.
n_radial (int) – Number of points in radial direction.
n_angular (int) – Number of points around the circumference.
device (str) – Compute device (‘cpu’ or ‘cuda’).
- Returns:
Mesh with n_manifold_dims=2, n_spatial_dims=3.
- Return type:
Mesh[2, 3]
- physicsnemo.mesh.primitives.surfaces.hemisphere.load(
- radius: float = 1.0,
- theta_resolution: int = 30,
- phi_resolution: int = 15,
- device: device | str = 'cpu',
Create a hemisphere surface in 3D space.
The normals point outward, away from the center of the sphere, as described in Orientation Conventions.
- Parameters:
radius (float) – Radius of the hemisphere.
theta_resolution (int) – Number of points around the equator.
phi_resolution (int) – Number of points from equator to pole.
device (str) – Compute device (‘cpu’ or ‘cuda’).
- Returns:
Mesh with n_manifold_dims=2, n_spatial_dims=3.
- Return type:
Mesh[2, 3]
- physicsnemo.mesh.primitives.surfaces.icosahedron_surface.load(
- radius: float = 1.0,
- device: device | str = 'cpu',
Create a regular icosahedron surface in 3D space.
- Parameters:
radius (float) – Distance from center to vertex.
device (str) – Compute device (‘cpu’ or ‘cuda’).
- Returns:
Mesh with n_manifold_dims=2, n_spatial_dims=3.
- Return type:
Mesh[2, 3]
- physicsnemo.mesh.primitives.surfaces.mobius_strip.load(
- radius: float = 1.0,
- width: float = 0.3,
- n_circ: int = 48,
- n_width: int = 5,
- device: device | str = 'cpu',
Create a Möbius strip surface in 3D space.
- Parameters:
radius (float) – Radius of the center circle.
width (float) – Width of the strip.
n_circ (int) – Number of points around the circle.
n_width (int) – Number of points across the width.
device (str) – Compute device (‘cpu’ or ‘cuda’).
- Returns:
Mesh with n_manifold_dims=2, n_spatial_dims=3 (non-orientable).
- Return type:
Mesh[2, 3]
- physicsnemo.mesh.primitives.surfaces.octahedron_surface.load(
- size: float = 1.0,
- device: device | str = 'cpu',
Create a regular octahedron surface in 3D space.
- Parameters:
size (float) – Distance from center to vertex.
device (str) – Compute device (‘cpu’ or ‘cuda’).
- Returns:
Mesh with n_manifold_dims=2, n_spatial_dims=3.
- Return type:
Mesh[2, 3]
- physicsnemo.mesh.primitives.surfaces.plane.load(
- size: float = 2.0,
- subdivisions: int = 10,
- normal: tuple[float, float, float] = (0.0, 0.0, 1.0),
- device: device | str = 'cpu',
Create a flat triangulated plane in 3D space.
The normals point in the direction of
normal, as described in Orientation Conventions.- Parameters:
size (float) – Size of the plane (length of each side).
subdivisions (int) – Number of subdivisions per edge. Creates (subdivisions+1)^2 vertices and 2*subdivisions^2 triangles.
normal (tuple[float, float, float]) – Normal vector to the plane (will be normalized). Must be finite and nonzero.
device (str) – Compute device (‘cpu’ or ‘cuda’).
- Returns:
Mesh with n_manifold_dims=2, n_spatial_dims=3.
- Return type:
Mesh[2, 3]
- physicsnemo.mesh.primitives.surfaces.sphere_icosahedral.load(
- radius: float = 1.0,
- subdivisions: int = 2,
- device: device | str = 'cpu',
Create a sphere by subdividing an icosahedron and projecting to sphere.
This method produces a more uniform triangulation than UV-parameterized spheres (no pole singularities). Each subdivision level quadruples the number of triangles.
- Parameters:
radius (float) – Radius of the sphere.
subdivisions (int) –
Number of subdivision levels to apply. Each level quadruples the triangle count:
0: 20 triangles (base icosahedron)
1: 80 triangles
2: 320 triangles
3: 1280 triangles
4: 5120 triangles
device (torch.device or str) – Compute device (‘cpu’ or ‘cuda’).
- Returns:
Mesh with n_manifold_dims=2, n_spatial_dims=3.
- Return type:
Mesh[2, 3]
Examples
>>> from physicsnemo.mesh.primitives.surfaces import sphere_icosahedral >>> mesh = sphere_icosahedral.load(radius=1.0, subdivisions=2) >>> mesh.n_manifold_dims, mesh.n_spatial_dims (2, 3) >>> mesh.n_cells # 20 * 4^2 = 320 triangles 320
- physicsnemo.mesh.primitives.surfaces.sphere_uv.load(
- radius: float = 1.0,
- theta_resolution: int = 30,
- phi_resolution: int = 30,
- device: device | str = 'cpu',
Create a UV sphere using latitude/longitude parameterization.
The sphere is generated using spherical coordinates:
\(\varphi\) (latitude): 0 at north pole, \(\pi\) at south pole.
\(\theta\) (longitude): 0 to \(2\pi\) around the equator.
Poles are handled with triangle fans; the body uses quad strips.
- Parameters:
radius (float) – Radius of the sphere.
theta_resolution (int) – Number of points around the equator (longitude divisions).
phi_resolution (int) – Number of latitude rings from pole to pole (including poles).
device (torch.device or str) – Compute device (‘cpu’ or ‘cuda’).
- Returns:
Mesh with n_manifold_dims=2, n_spatial_dims=3.
- Return type:
Mesh[2, 3]
Examples
>>> from physicsnemo.mesh.primitives.surfaces import sphere_uv >>> mesh = sphere_uv.load() >>> mesh.n_manifold_dims, mesh.n_spatial_dims (2, 3)
- physicsnemo.mesh.primitives.surfaces.tetrahedron_surface.load(
- side_length: float = 1.0,
- device: device | str = 'cpu',
Create a regular tetrahedron surface in 3D space.
- Parameters:
side_length (float) – Length of each edge.
device (str) – Compute device (‘cpu’ or ‘cuda’).
- Returns:
Mesh with n_manifold_dims=2, n_spatial_dims=3.
- Return type:
Mesh[2, 3]
- physicsnemo.mesh.primitives.surfaces.torus.load(
- major_radius: float = 1.0,
- minor_radius: float = 0.3,
- n_major: int = 48,
- n_minor: int = 24,
- device: device | str = 'cpu',
Create a torus surface in 3D space.
The normals point outward, away from the center of the tube, as described in Orientation Conventions.
- Parameters:
major_radius (float) – Distance from center to tube center.
minor_radius (float) – Radius of the tube.
n_major (int) – Number of points around the major circle.
n_minor (int) – Number of points around the minor circle.
device (str) – Compute device (‘cpu’ or ‘cuda’).
- Returns:
Mesh with n_manifold_dims=2, n_spatial_dims=3.
- Return type:
Mesh[2, 3]
Volumes#
- physicsnemo.mesh.primitives.volumes.cube_volume.load(
- size: float = 1.0,
- subdivisions: int = 5,
- device: device | str = 'cpu',
Create a tetrahedral volume mesh of a cube.
The cube is divided into a regular grid of smaller cubes, and each small cube is split into 6 tetrahedra using the Kuhn triangulation. This triangulation naturally produces matching faces between adjacent cubes, ensuring a valid watertight volume mesh.
Every tetrahedron has a positive signed volume, as described in Orientation Conventions.
- Parameters:
size (float) – Side length of the cube.
subdivisions (int) – Number of subdivisions per edge.
device (str) – Compute device (‘cpu’ or ‘cuda’).
- Returns:
Mesh with n_manifold_dims=3, n_spatial_dims=3.
- Return type:
Mesh[3, 3]
- physicsnemo.mesh.primitives.volumes.cylinder_volume.load(
- radius: float = 1.0,
- height: float = 2.0,
- resolution: int = 20,
- device: device | str = 'cpu',
Create a tetrahedral volume mesh of a cylinder.
The interior is filled with a fan of tetrahedra from the center to each triangle of a PyVista cylinder surface. The cylinder is convex, so the tetrahedra fill it without overlap.
- Parameters:
radius (float) – Radius of the cylinder.
height (float) – Height of the cylinder (centered at origin).
resolution (int) – Controls the density of points (higher = more tetrahedra).
device (str) – Compute device (‘cpu’ or ‘cuda’).
- Returns:
Mesh with n_manifold_dims=3, n_spatial_dims=3.
- Return type:
Mesh[3, 3]
- physicsnemo.mesh.primitives.volumes.sphere_volume.load(
- radius: float = 1.0,
- resolution: int = 20,
- device: device | str = 'cpu',
Create a tetrahedral volume mesh of a sphere.
The interior is filled with a fan of tetrahedra from the center to each triangle of a PyVista sphere surface. The sphere is convex, so the tetrahedra fill it without overlap.
- Parameters:
radius (float) – Radius of the sphere.
resolution (int) – Controls the density of points (higher = more tetrahedra).
device (str) – Compute device (‘cpu’ or ‘cuda’).
- Returns:
Mesh with n_manifold_dims=3, n_spatial_dims=3.
- Return type:
Mesh[3, 3]
- physicsnemo.mesh.primitives.volumes.tetrahedron_volume.load(
- side_length: float = 1.0,
- device: device | str = 'cpu',
Create a single regular tetrahedron volume.
- Parameters:
side_length (float) – Length of each edge.
device (str) – Compute device (‘cpu’ or ‘cuda’).
- Returns:
Mesh with n_manifold_dims=3, n_spatial_dims=3, n_cells=1.
- Return type:
Mesh[3, 3]
Procedural Meshes#
- physicsnemo.mesh.primitives.procedural.lumpy_ball.load(
- radius: float = 1.0,
- n_shells: int = 3,
- subdivisions: int = 2,
- noise_amplitude: float = 0.5,
- seed: int = 0,
- device: device | str = 'cpu',
Create a lumpy ball volume mesh.
Builds a solid ball from concentric icosahedral shells connected by tetrahedra. The mesh has naturally graded cell sizes (smaller near center, larger at surface) and mixed vertex valences inherited from the icosahedral structure.
- Parameters:
radius (float) – Outer radius of the ball.
n_shells (int) – Number of concentric shells (more = finer radial resolution). Must be at least 1.
subdivisions (int) – Subdivision level per shell (more = finer angular resolution). Each level quadruples the number of faces.
noise_amplitude (float) – Radial noise amplitude. 0 = perfect sphere, >0 = lumpy. Uses log-normal scaling like lumpy_sphere. Raises
ValueErrorif the noise makes the surface not star-shaped about the center.seed (int) – Random seed for noise reproducibility.
device (torch.device or str) – Compute device (‘cpu’ or ‘cuda’).
- Returns:
Mesh with n_manifold_dims=3, n_spatial_dims=3.
- Return type:
Mesh[3, 3]
Examples
>>> from physicsnemo.mesh.primitives.procedural import lumpy_ball >>> mesh = lumpy_ball.load(radius=1.0, n_shells=2, subdivisions=1) >>> mesh.n_manifold_dims, mesh.n_spatial_dims (3, 3) >>> mesh.n_cells # 80 faces * (3*2 - 2) = 320 320
- physicsnemo.mesh.primitives.procedural.lumpy_sphere.load(
- radius: float = 1.0,
- subdivisions: int = 3,
- noise_amplitude: float = 0.5,
- seed: int = 0,
- device: str = 'cpu',
Create a lumpy sphere by adding radial noise to a sphere.
- Parameters:
radius (float, optional) – Base radius of the sphere
subdivisions (int, optional) – Number of subdivision levels
noise_amplitude (float, optional) – Amplitude of radial noise
seed (int, optional) – Random seed for reproducibility
device (str, optional) – Compute device (‘cpu’ or ‘cuda’)
- Returns:
Mesh with n_manifold_dims=2, n_spatial_dims=3
- Return type:
Mesh[2, 3]
- physicsnemo.mesh.primitives.procedural.noisy_mesh.load(
- base_mesh: Mesh,
- noise_scale: float = 0.1,
- seed: int = 0,
Add Gaussian noise to mesh vertex positions.
- physicsnemo.mesh.primitives.procedural.perturbed_grid.load(
- n_x: int = 11,
- n_y: int = 11,
- perturbation_scale: float = 0.05,
- seed: int = 0,
- device: device | str = 'cpu',
Create a perturbed structured grid in 2D space.
Before the perturbation, every triangle is wound counterclockwise, as described in Orientation Conventions.
- Parameters:
n_x (int) – Number of points in x-direction.
n_y (int) – Number of points in y-direction.
perturbation_scale (float) – Standard deviation of the random perturbation of interior points, as a fraction of the grid spacing. Values above about 0.1 can fold (invert) cells.
seed (int) – Random seed for reproducibility.
device (str) – Compute device (‘cpu’ or ‘cuda’).
- Returns:
Mesh with n_manifold_dims=2, n_spatial_dims=2.
- Return type:
Mesh[2, 2]
Basic Meshes#
- physicsnemo.mesh.primitives.basic.single_edge_2d.load(
- device: device | str = 'cpu',
Create a mesh with a single edge in 2D space.
- Parameters:
device (str) – Compute device (‘cpu’ or ‘cuda’).
- Returns:
Mesh with n_manifold_dims=1, n_spatial_dims=2, n_cells=1.
- Return type:
Mesh[1, 2]
- physicsnemo.mesh.primitives.basic.single_edge_3d.load(
- device: device | str = 'cpu',
Create a mesh with a single edge in 3D space.
- Parameters:
device (str) – Compute device (‘cpu’ or ‘cuda’).
- Returns:
Mesh with n_manifold_dims=1, n_spatial_dims=3, n_cells=1.
- Return type:
Mesh[1, 3]
- physicsnemo.mesh.primitives.basic.single_point_2d.load(
- device: device | str = 'cpu',
Create a mesh with a single point in 2D space.
- Parameters:
device (str) – Compute device (‘cpu’ or ‘cuda’).
- Returns:
Mesh with n_manifold_dims=0, n_spatial_dims=2, n_cells=1.
- Return type:
Mesh[0, 2]
- physicsnemo.mesh.primitives.basic.single_point_3d.load(
- device: device | str = 'cpu',
Create a mesh with a single point in 3D space.
- Parameters:
device (str) – Compute device (‘cpu’ or ‘cuda’).
- Returns:
Mesh with n_manifold_dims=0, n_spatial_dims=3, n_cells=1.
- Return type:
Mesh[0, 3]
- physicsnemo.mesh.primitives.basic.single_tetrahedron.load(
- device: device | str = 'cpu',
Create a mesh with a single tetrahedron in 3D space.
- Parameters:
device (str) – Compute device (‘cpu’ or ‘cuda’).
- Returns:
Mesh with n_manifold_dims=3, n_spatial_dims=3, n_cells=1.
- Return type:
Mesh[3, 3]
- physicsnemo.mesh.primitives.basic.single_triangle_2d.load(
- device: device | str = 'cpu',
Create a mesh with a single triangle in 2D space.
- Parameters:
device (str) – Compute device (‘cpu’ or ‘cuda’).
- Returns:
Mesh with n_manifold_dims=2, n_spatial_dims=2, n_cells=1.
- Return type:
Mesh[2, 2]
- physicsnemo.mesh.primitives.basic.single_triangle_3d.load(
- device: device | str = 'cpu',
Create a mesh with a single triangle in 3D space.
- Parameters:
device (str) – Compute device (‘cpu’ or ‘cuda’).
- Returns:
Mesh with n_manifold_dims=2, n_spatial_dims=3, n_cells=1.
- Return type:
Mesh[2, 3]
- physicsnemo.mesh.primitives.basic.three_edges_2d.load(
- device: device | str = 'cpu',
Create a polyline with three edges in 2D space.
- Parameters:
device (str) – Compute device (‘cpu’ or ‘cuda’).
- Returns:
Mesh with n_manifold_dims=1, n_spatial_dims=2, n_cells=3.
- Return type:
Mesh[1, 2]
- physicsnemo.mesh.primitives.basic.three_edges_3d.load(
- device: device | str = 'cpu',
Create a polyline with three edges in 3D space.
- Parameters:
device (str) – Compute device (‘cpu’ or ‘cuda’).
- Returns:
Mesh with n_manifold_dims=1, n_spatial_dims=3, n_cells=3.
- Return type:
Mesh[1, 3]
- physicsnemo.mesh.primitives.basic.three_points_2d.load(
- device: device | str = 'cpu',
Create a mesh with three points in 2D space.
- Parameters:
device (str) – Compute device (‘cpu’ or ‘cuda’).
- Returns:
Mesh with n_manifold_dims=0, n_spatial_dims=2, n_cells=3.
- Return type:
Mesh[0, 2]
- physicsnemo.mesh.primitives.basic.three_points_3d.load(
- device: device | str = 'cpu',
Create a mesh with three points in 3D space.
- Parameters:
device (str) – Compute device (‘cpu’ or ‘cuda’).
- Returns:
Mesh with n_manifold_dims=0, n_spatial_dims=3, n_cells=3.
- Return type:
Mesh[0, 3]
- physicsnemo.mesh.primitives.basic.two_tetrahedra.load(
- device: device | str = 'cpu',
Create a mesh with two tetrahedra in 3D space.
The tetrahedra share a common triangular face, forming a simple volumetric region.
- Parameters:
device (str) – Compute device (‘cpu’ or ‘cuda’).
- Returns:
Mesh with n_manifold_dims=3, n_spatial_dims=3, n_cells=2.
- Return type:
Mesh[3, 3]
- physicsnemo.mesh.primitives.basic.two_triangles_2d.load(
- device: device | str = 'cpu',
Create a mesh with two triangles in 2D space.
The triangles share a common edge, forming a simple quadrilateral region triangulated into two triangles.
- Parameters:
device (str) – Compute device (‘cpu’ or ‘cuda’).
- Returns:
Mesh with n_manifold_dims=2, n_spatial_dims=2, n_cells=2.
- Return type:
Mesh[2, 2]
- physicsnemo.mesh.primitives.basic.two_triangles_3d.load(
- device: device | str = 'cpu',
Create a mesh with two triangles in 3D space.
The triangles share a common edge, forming a simple surface patch.
- Parameters:
device (str) – Compute device (‘cpu’ or ‘cuda’).
- Returns:
Mesh with n_manifold_dims=2, n_spatial_dims=3, n_cells=2.
- Return type:
Mesh[2, 3]
PyVista Datasets#
- physicsnemo.mesh.primitives.pyvista_datasets.airplane.load(
- device: device | str = 'cpu',
Load airplane surface mesh from PyVista examples.
This is a classic test case for surface mesh algorithms. PyVista caches the downloaded file automatically.
- Parameters:
device (str) – Compute device (‘cpu’ or ‘cuda’).
- Returns:
Mesh with n_manifold_dims=2, n_spatial_dims=3.
- Return type:
Mesh[2, 3]
- physicsnemo.mesh.primitives.pyvista_datasets.ant.load(
- device: device | str = 'cpu',
Load ant surface mesh from PyVista examples.
PyVista caches the downloaded file automatically.
- Parameters:
device (str) – Compute device (‘cpu’ or ‘cuda’).
- Returns:
Mesh with n_manifold_dims=2, n_spatial_dims=3.
- Return type:
Mesh[2, 3]
- physicsnemo.mesh.primitives.pyvista_datasets.bunny.load(
- device: device | str = 'cpu',
Load Stanford bunny surface mesh from PyVista examples.
The Stanford bunny is a classic test model in computer graphics. PyVista caches the downloaded file automatically.
- Parameters:
device (str) – Compute device (‘cpu’ or ‘cuda’).
- Returns:
Mesh with n_manifold_dims=2, n_spatial_dims=3.
- Return type:
Mesh[2, 3]
- physicsnemo.mesh.primitives.pyvista_datasets.cow.load(
- device: device | str = 'cpu',
Load cow surface mesh from PyVista examples.
The cow mesh is a classic test case that originally contains both triangular and quadrilateral cells, automatically triangulated during conversion.
PyVista caches the downloaded file automatically.
- Parameters:
device (str) – Compute device (‘cpu’ or ‘cuda’).
- Returns:
Mesh with n_manifold_dims=2, n_spatial_dims=3.
- Return type:
Mesh[2, 3]
- physicsnemo.mesh.primitives.pyvista_datasets.globe.load(
- device: device | str = 'cpu',
Load globe surface mesh from PyVista examples.
A textured sphere representing Earth. Note that texture coordinates are lost during conversion, but the geometry is preserved.
- Parameters:
device (str) – Compute device (‘cpu’ or ‘cuda’).
- Returns:
Mesh with n_manifold_dims=2, n_spatial_dims=3.
- Return type:
Mesh[2, 3]
- physicsnemo.mesh.primitives.pyvista_datasets.hexbeam.load(
- device: device | str = 'cpu',
Load hexahedral beam mesh from PyVista examples.
The hexahedral cells are automatically tessellated into tetrahedra during conversion.
- Parameters:
device (str) – Compute device (‘cpu’ or ‘cuda’).
- Returns:
Mesh with n_manifold_dims=3, n_spatial_dims=3.
- Return type:
Mesh[3, 3]
- physicsnemo.mesh.primitives.pyvista_datasets.tetbeam.load(
- device: device | str = 'cpu',
Load tetrahedral beam volume mesh from PyVista examples.
A classic finite element test case consisting of tetrahedral elements.
The PyVista tetrahedra are inverted, so this function reorders their vertices to give every tetrahedron a positive signed volume, as described in Orientation Conventions.
- Parameters:
device (str) – Compute device (‘cpu’ or ‘cuda’).
- Returns:
Mesh with n_manifold_dims=3, n_spatial_dims=3.
- Return type:
Mesh[3, 3]
Text#
- physicsnemo.mesh.primitives.text.text_1d_2d(
- text: str = 'physicsnemo.mesh',
- font_size: float = 12.0,
- samples_per_unit: float = 10,
- max_segment_length: float = 0.25,
- device: device | str = 'cpu',
Render text as 1D curve in 2D space (boundary path only).
Converts text to a polyline mesh representing the outline of each letter.
- Parameters:
text (str, optional) – Text string to render
font_size (float, optional) – Font size in arbitrary units
samples_per_unit (float, optional) – Density of curve sampling for Bezier curves
max_segment_length (float, optional) – Maximum edge length after subdivision
device (torch.device | str, optional) – Device for mesh tensors (‘cpu’, ‘cuda’, or torch.device)
- Returns:
Mesh with n_manifold_dims=1, n_spatial_dims=2 (polyline in 2D)
- Return type:
Mesh[1, 2]
Examples
>>> mesh = text_1d_2d("Hello", font_size=10.0) >>> assert mesh.n_manifold_dims == 1 >>> assert mesh.n_spatial_dims == 2
- physicsnemo.mesh.primitives.text.text_2d_2d(
- text: str = 'physicsnemo.mesh',
- font_size: float = 12.0,
- samples_per_unit: float = 10,
- max_segment_length: float = 0.25,
- device: device | str = 'cpu',
Render text as 2D triangulated surface in 2D space (filled letters).
Converts text to a filled mesh with proper hole handling for letters like ‘o’, ‘e’, ‘a’. Uses Delaunay triangulation and shoelace formula for hole detection.
- Parameters:
text (str, optional) – Text string to render
font_size (float, optional) – Font size in arbitrary units
samples_per_unit (float, optional) – Density of curve sampling for Bezier curves
max_segment_length (float, optional) – Maximum edge length after subdivision
device (torch.device | str, optional) – Device for mesh tensors (‘cpu’, ‘cuda’, or torch.device)
- Returns:
Mesh with n_manifold_dims=2, n_spatial_dims=2 (filled text in 2D plane)
- Return type:
Mesh[2, 2]
Examples
>>> mesh = text_2d_2d("Hello", font_size=10.0) >>> assert mesh.n_manifold_dims == 2 >>> assert mesh.n_spatial_dims == 2
- physicsnemo.mesh.primitives.text.text_2d_3d(
- text: str = 'physicsnemo.mesh',
- font_size: float = 12.0,
- samples_per_unit: float = 10,
- max_segment_length: float = 0.25,
- extrusion_height: float = 2.0,
- device: device | str = 'cpu',
Render text as 2D boundary surface in 3D space (hollow extruded text).
Creates the surface of 3D text by extracting the boundary from an extruded tetrahedral volume.
- Parameters:
text (str, optional) – Text string to render
font_size (float, optional) – Font size in arbitrary units
samples_per_unit (float, optional) – Density of curve sampling for Bezier curves
max_segment_length (float, optional) – Maximum edge length after subdivision
extrusion_height (float, optional) – Height to extrude in z-direction
device (torch.device | str, optional) – Device for mesh tensors (‘cpu’, ‘cuda’, or torch.device)
- Returns:
Mesh with n_manifold_dims=2, n_spatial_dims=3 (triangulated surface in 3D)
- Return type:
Mesh[2, 3]
Examples
>>> mesh = text_2d_3d("Hello", font_size=10.0, extrusion_height=1.0) >>> assert mesh.n_manifold_dims == 2 >>> assert mesh.n_spatial_dims == 3
- physicsnemo.mesh.primitives.text.text_3d_3d(
- text: str = 'physicsnemo.mesh',
- font_size: float = 12.0,
- samples_per_unit: float = 10,
- max_segment_length: float = 0.25,
- extrusion_height: float = 2.0,
- device: device | str = 'cpu',
Render text as 3D tetrahedral volume (solid extruded text).
Creates solid 3D text by triangulating in 2D, embedding to 3D, and extruding along the z-axis.
- Parameters:
text (str, optional) – Text string to render
font_size (float, optional) – Font size in arbitrary units
samples_per_unit (float, optional) – Density of curve sampling for Bezier curves
max_segment_length (float, optional) – Maximum edge length after subdivision
extrusion_height (float, optional) – Height to extrude in z-direction
device (torch.device | str, optional) – Device for mesh tensors (‘cpu’, ‘cuda’, or torch.device)
- Returns:
Mesh with n_manifold_dims=3, n_spatial_dims=3 (solid tetrahedral volume)
- Return type:
Mesh[3, 3]
Examples
>>> mesh = text_3d_3d("Hello", font_size=10.0, extrusion_height=1.0) >>> assert mesh.n_manifold_dims == 3 >>> assert mesh.n_spatial_dims == 3