Skip to content

Geometry (3D)¤

Mesh-based geometries¤

Boolean / CSG operations¤

Geometry3DFromCAD supports boolean operations via operator overloading:

  • A + B: union (\(\Omega = \Omega_A \cup \Omega_B\))
  • A - B: difference (\(\Omega = \Omega_A \setminus \Omega_B\))
  • A & B: intersection (\(\Omega = \Omega_A \cap \Omega_B\))

Example

import phydrax as phx

# In real workflows you can load meshes from disk via Geometry3DFromCAD("path.stl").
# For a runnable example without external files, use primitives (they produce CAD-backed geometries).
A = phx.domain.Sphere(center=(0.0, 0.0, 0.0), radius=1.0)
B = phx.domain.Cube(center=(0.25, 0.0, 0.0), side=1.2)

#     U = A + B
#     D = A - B
#     I = A & B

phydrax.domain.Geometry3DFromCAD ¤

A 3D geometry represented by a watertight surface mesh.

This class treats a closed triangulated surface mesh as defining a solid region \(\Omega\subset\mathbb{R}^3\). Sampling routines draw:

  • boundary points \(x\in\partial\Omega\) by sampling triangles proportional to their area;
  • interior points \(x\in\Omega\) via mesh-based strategies (see sample_interior).

A smooth signed distance-like function \(\phi(x)\) is provided via adf, and is used for containment tests and for estimating boundary normals.

__init__(mesh: trimesh.base.Trimesh | meshio._mesh.Mesh | pathlib.Path | str, *, recenter: bool = False, immersed: bool = False) ¤
__add__(other: Geometry3DFromCAD) -> Geometry3DFromCAD ¤

Boolean union of two solids: \(\Omega = \Omega_1 \cup \Omega_2\).

__sub__(other: Geometry3DFromCAD) -> Geometry3DFromCAD ¤

Boolean difference of two solids: \(\Omega = \Omega_1 \setminus \Omega_2\).

__and__(other: Geometry3DFromCAD) -> Geometry3DFromCAD ¤

Boolean intersection of two solids: \(\Omega = \Omega_1 \cap \Omega_2\).

sample_interior(num_points: int, *, where: collections.abc.Callable | None = None, sampler: str = 'latin_hypercube', key: Key[Array, ''] = jr.key(0)) -> Array ¤

Sample points from the interior of \(\Omega\).

Returns an array of shape (num_points, 3) containing points in \(\Omega\subset\mathbb{R}^3\), optionally filtered by where(x).

sample_boundary(num_points: int, *, where: collections.abc.Callable | None = None, sampler: str = 'latin_hypercube', key: Key[Array, ''] = jr.key(0)) -> Array ¤

Sample points from the boundary \(\partial\Omega\).

Returns an array of shape (num_points, 3) containing boundary points, optionally filtered by where(x).

translate(offset: ArrayLike) -> Geometry3DFromCAD ¤

Return a translated copy of the geometry.

Applies the rigid transform \(x \mapsto x + b\) with translation vector \(b\in\mathbb{R}^3\).

scale(factor: ArrayLike) -> Geometry3DFromCAD ¤

Return a uniformly scaled copy of the geometry.

Applies the dilation \(x \mapsto s x\) with scalar \(s>0\).


phydrax.domain.Geometry3DFromPointCloud(points: ArrayLike, *, recenter: bool = True, nbr_sz: int | None = None, radius: float | None = None, sample_spacing: float | None = None, progress_bar: bool = False) -> Geometry3DFromCAD ¤

Reconstruct a 3D mesh geometry from a surface point cloud.

Interprets points as samples from (or near) the surface \(\partial\Omega\) of an unknown solid \(\Omega\subset\mathbb{R}^3\). A triangulated surface is reconstructed and used to build a Geometry3DFromCAD.

Arguments:

  • points: Array-like of shape (N, 3) (or (N, >=3), where only the first three coordinates are used).
  • recenter: Whether to recenter the reconstructed mesh coordinates.
  • nbr_sz: Optional PyVista reconstruct_surface control (passed through when supported).
  • radius: Optional PyVista reconstruct_surface control (passed through when supported).
  • sample_spacing: Optional PyVista reconstruct_surface control (passed through when supported).
  • progress_bar: Optional PyVista reconstruct_surface control (passed through when supported).

phydrax.domain.Geometry3DFromDEM(points_or_grid: ArrayLike, *, recenter: bool = True, alpha: float | None = None, tol: float | None = None, bound: float | str | None = None, progress_bar: bool = False, extrude_depth: float = 1.0, x: ArrayLike | None = None, y: ArrayLike | None = None) -> Geometry3DFromCAD ¤

Create a (roughly) watertight 3D geometry from a 2.5D DEM.

The input is interpreted as a height field \(z=z(x,y)\) sampled on a grid or as scattered \((x,y,z)\) points. A triangulated surface is constructed and (when supported) extruded downward to produce a closed solid suitable for sampling.

Arguments:

  • points_or_grid: Either a grid of shape (ny, nx) with heights, or an array of points of shape (N, 3) (or (N, >=3)).
  • recenter: Whether to recenter the reconstructed mesh coordinates.
  • alpha: Optional PyVista delaunay_2d control (passed through when supported).
  • tol: Optional PyVista delaunay_2d control (passed through when supported).
  • bound: Optional PyVista delaunay_2d control (passed through when supported).
  • progress_bar: Optional PyVista delaunay_2d control (passed through when supported).
  • extrude_depth: Extrusion depth used to "close" the surface.
  • x: Optional coordinate vector for the height grid.
  • y: Optional coordinate vector for the height grid.

phydrax.domain.Geometry3DFromLidarScene(points: ArrayLike, *, recenter: bool = True, roi: tuple[float, float, float, float, float, float] | None = None, voxel_size: float | None = None, nbr_sz: int | None = None, radius: float | None = None, sample_spacing: float | None = None, progress_bar: bool = False, close_depth: float = 0.5) -> Geometry3DFromCAD ¤

Construct a mesh geometry from LiDAR scene points.

This helper optionally:

  • crops the point cloud to a region of interest (ROI),
  • voxel-downsamples the points,
  • reconstructs a surface \(\partial\Omega\),
  • extrudes it to obtain a closed solid.

Arguments:

  • points: Array-like of shape (N, 3) (or (N, >=3)).
  • recenter: Whether to recenter the reconstructed mesh coordinates.
  • roi: Optional axis-aligned ROI (xmin, xmax, ymin, ymax, zmin, zmax).
  • voxel_size: Optional voxel downsampling size.
  • nbr_sz: Optional PyVista reconstruct_surface control (passed through when supported).
  • radius: Optional PyVista reconstruct_surface control (passed through when supported).
  • sample_spacing: Optional PyVista reconstruct_surface control (passed through when supported).
  • progress_bar: Optional PyVista reconstruct_surface control (passed through when supported).
  • close_depth: Extrusion depth used to close the reconstructed surface.

Primitives¤

phydrax.domain.Sphere(center: tuple[float, float, float], radius: float) -> Geometry3DFromCAD ¤

A solid sphere geometry.

Defines

\[ \Omega = \{x\in\mathbb{R}^3:\|x-c\|_2 \le r\}. \]

Arguments:

  • center: The center \(c\in\mathbb{R}^3\).
  • radius: The radius \(r>0\).

Returns:

A Geometry3DFromCAD representing the sphere.


phydrax.domain.Ellipsoid(center: tuple[float, float, float], radii: tuple[float, float, float]) -> Geometry3DFromCAD ¤

A solid ellipsoid geometry.

Defines

\[ \Omega = \left\{x\in\mathbb{R}^3: \left(\frac{x_1-c_1}{r_1}\right)^2+ \left(\frac{x_2-c_2}{r_2}\right)^2+ \left(\frac{x_3-c_3}{r_3}\right)^2 \le 1 \right\}. \]

Arguments:

  • center: The center \(c\in\mathbb{R}^3\).
  • radii: Semi-axis lengths \((r_1,r_2,r_3)\).

Returns:

A Geometry3DFromCAD representing the ellipsoid.


phydrax.domain.Cuboid(center: tuple[float, float, float], dimensions: tuple[float, float, float]) -> Geometry3DFromCAD ¤

An axis-aligned box (cuboid) geometry.

Defines

\[ \Omega = \{x\in\mathbb{R}^3: |x_1-c_1|\le \tfrac{d_x}{2},\ |x_2-c_2|\le \tfrac{d_y}{2},\ |x_3-c_3|\le \tfrac{d_z}{2}\}. \]

Arguments:

  • center: The center \(c\in\mathbb{R}^3\).
  • dimensions: Side lengths \((d_x,d_y,d_z)\).

Returns:

A Geometry3DFromCAD representing the cuboid.


phydrax.domain.Cube(center: tuple[float, float, float], side: float) -> Geometry3DFromCAD ¤

An axis-aligned cube geometry.

This is the special case of Cuboid with all side lengths equal to side.

Arguments:

  • center: The center \(c\in\mathbb{R}^3\).
  • side: Side length \(s>0\).

Returns:

A Geometry3DFromCAD representing the cube.


phydrax.domain.Cylinder(face_center: collections.abc.Sequence | ArrayLike, axis: collections.abc.Sequence | ArrayLike, radius: float, angle: float = 6.283185307179586) -> Geometry3DFromCAD ¤

A solid cylinder geometry.

Constructs a cylinder by extruding a disk of radius \(r\) along an axis vector \(a\in\mathbb{R}^3\) of length \(h=\|a\|_2\) starting from face_center.

Arguments:

  • face_center: Center of the starting face.
  • axis: Extrusion vector \(a\) (its direction sets the cylinder axis).
  • radius: Radius \(r>0\).
  • angle: Angular opening in radians (currently full cylinders are the common use).

Returns:

A Geometry3DFromCAD representing the cylinder.


phydrax.domain.Cone(base_center: collections.abc.Sequence | ArrayLike, axis: collections.abc.Sequence | ArrayLike, radius0: float, radius1: float = 0.0, angle: float = 6.283185307179586) -> Geometry3DFromCAD ¤

A solid cone (or conical frustum) geometry.

Constructs a cone/frustum by extruding a circle of radius radius0 along an axis vector, linearly varying the radius to radius1 at the end.

Arguments:

  • base_center: Center of the base face.
  • axis: Extrusion vector (its length sets the height).
  • radius0: Base radius \(r_0\).
  • radius1: Top radius \(r_1\) (use \(0\) for a pointed cone).
  • angle: Angular opening in radians.

Returns:

A Geometry3DFromCAD representing the cone.


phydrax.domain.Torus(center: collections.abc.Sequence | ArrayLike, inner_radius: float, outer_radius: float, angle: float = 6.283185307179586) -> Geometry3DFromCAD ¤

A solid torus geometry.

This helper interprets inner_radius/outer_radius as the inner/outer radii of the torus tube. It converts them to the usual major/minor radii via \(R=\tfrac{1}{2}(r_{\texttt{in}}+r_{\texttt{out}})\) and \(r=\tfrac{1}{2}(r_{\texttt{out}}-r_{\texttt{in}})\).

Arguments:

  • center: Center translation of the torus.
  • inner_radius: Inner tube radius \(r_{\texttt{in}}\).
  • outer_radius: Outer tube radius \(r_{\texttt{out}}\).
  • angle: Angular opening in radians.

Returns:

A Geometry3DFromCAD representing the torus.


phydrax.domain.Wedge(x0: collections.abc.Sequence | ArrayLike, extends: collections.abc.Sequence | ArrayLike, top_extent: float) -> Geometry3DFromCAD ¤

A right angular wedge geometry.

Constructs a wedge-like solid defined by a right-angle corner and edge extents. This is useful for simple ramp/wedge test geometries in mechanics and CFD.

Arguments:

  • x0: Coordinates of the reference corner.
  • extends: Edge extents along each axis.
  • top_extent: Controls the top face extent along the \(x\) direction.

Returns:

A Geometry3DFromCAD representing the wedge.