Skip to content

Geometry (2D)¤

Mesh-based geometries¤

Boolean / CSG operations¤

Geometry2DFromCAD 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 Geometry2DFromCAD("path.stl").
# For a runnable example without external files, use primitives (they produce CAD-backed geometries).
A = phx.domain.Circle(center=(0.0, 0.0), radius=1.0)
B = phx.domain.Square(center=(0.25, 0.0), side=1.0)

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

phydrax.domain.Geometry2DFromCAD ¤

A 2D geometry represented by a triangulated surface mesh.

This class treats a watertight triangulated mesh as defining a planar region \(\Omega\subset\mathbb{R}^2\). Sampling routines draw:

  • interior points \(x\in\Omega\) by sampling triangles proportional to their area;
  • boundary points \(x\in\partial\Omega\) by sampling edges proportional to length.

The geometry also provides a smooth signed distance-like function \(\phi(x)\) (via adf) that is used for containment tests and for estimating normals when needed.

__init__(mesh: meshio._mesh.Mesh | pathlib.Path | str, *, recenter: bool = True) ¤
__add__(other: Geometry2DFromCAD) -> Geometry2DFromCAD ¤

Union of two 2D geometries via extruded 3D CSG.

__sub__(other: Geometry2DFromCAD) -> Geometry2DFromCAD ¤

Difference (self minus other) of two 2D geometries via extruded 3D CSG.

__and__(other: Geometry2DFromCAD) -> Geometry2DFromCAD ¤

Intersection of two 2D geometries via extruded 3D CSG.

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

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

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

The optional interior_edge_fraction can be used to bias samples towards interior edges (useful for capturing sharp features in PDE solutions).

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, 2) containing boundary points in \(\partial\Omega\), optionally filtered by where(x).


phydrax.domain.Geometry2DFromPointCloud(points: ArrayLike, *, recenter: bool = True, alpha: float | None = None, tol: float | None = None, offset: float | None = None, bound: float | str | None = None, progress_bar: bool = False) -> Geometry2DFromCAD ¤

Reconstruct a 2D mesh geometry from a boundary point cloud.

Interprets points as samples from (or near) the boundary \(\partial\Omega\) of an unknown planar region \(\Omega\subset\mathbb{R}^2\). A triangulation is constructed in the plane and used to build a Geometry2DFromCAD instance.

Arguments:

  • points: Array-like of shape (N, 2) (or (N, >=2), where only the first two coordinates are used).
  • 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).
  • offset: 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).

Primitives¤

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

A disk (filled circle) geometry.

Defines the set

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

with center \(c\in\mathbb{R}^2\) and radius \(r>0\).

Arguments:

  • center: The center \(c=(c_x,c_y)\).
  • radius: The radius \(r\).

Returns:

A Geometry2DFromCAD representing the circle.


phydrax.domain.Ellipse(center: tuple[float, float], x_radius: float, y_radius: float) -> Geometry2DFromCAD ¤

A filled ellipse geometry.

Defines the set

\[ \Omega = \left\{(x,y)\in\mathbb{R}^2 : \left(\frac{x-c_x}{r_x}\right)^2 + \left(\frac{y-c_y}{r_y}\right)^2 \le 1 \right\}. \]

Arguments:

  • center: The center \(c=(c_x,c_y)\).
  • x_radius: Semi-axis length \(r_x>0\).
  • y_radius: Semi-axis length \(r_y>0\).

Returns:

A Geometry2DFromCAD representing the ellipse.


phydrax.domain.Rectangle(center: tuple[float, float], width: float, height: float) -> Geometry2DFromCAD ¤

An axis-aligned rectangle geometry.

Defines the set

\[ \Omega = \{(x,y)\in\mathbb{R}^2 : |x-c_x|\le \tfrac{w}{2},\ |y-c_y|\le \tfrac{h}{2}\}. \]

Arguments:

  • center: The center \(c=(c_x,c_y)\).
  • width: Width \(w>0\).
  • height: Height \(h>0\).

Returns:

A Geometry2DFromCAD representing the rectangle.


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

An axis-aligned square geometry.

This is the special case of Rectangle with width = height = side.

Arguments:

  • center: The center \(c=(c_x,c_y)\).
  • side: Side length \(s>0\).

Returns:

A Geometry2DFromCAD representing the square.


phydrax.domain.Polygon(vertices: collections.abc.Sequence[tuple[float, float]]) -> Geometry2DFromCAD ¤

A polygonal planar region defined by its vertices.

Given vertices \((v_1,\dots,v_n)\) ordered around the boundary (clockwise or counter-clockwise), this constructs a planar region whose boundary is the piecewise-linear closed curve connecting consecutive vertices.

Arguments:

  • vertices: Sequence of vertices \(v_i\in\mathbb{R}^2\).

Returns:

A Geometry2DFromCAD representing the polygon.


phydrax.domain.Triangle(vertices: collections.abc.Sequence[tuple[float, float]]) -> Geometry2DFromCAD ¤

A triangular planar region defined by three vertices.

Arguments:

  • vertices: The three vertices \(v_1,v_2,v_3\in\mathbb{R}^2\).

Returns:

A Geometry2DFromCAD representing the triangle.