polytopax.ConvexHull
- class polytopax.ConvexHull(vertices: ~jax.Array, faces: ~jax.Array | None = None, algorithm_info: dict[str, ~typing.Any] = <factory>)[source]
JAX-compatible ConvexHull class with object-oriented API.
This class provides a high-level interface for convex hull operations, including geometric queries, property computation, and transformations. It is designed to be compatible with JAX transformations (jit, grad, vmap).
Example
>>> import jax.numpy as jnp >>> from polytopax import ConvexHull >>> points = jnp.array([[0, 0], [1, 0], [0, 1], [1, 1]]) >>> hull = ConvexHull.from_points(points) >>> print(f"Volume: {hull.volume():.4f}") >>> print(f"Centroid: {hull.centroid()}")
- __init__(vertices: ~jax.Array, faces: ~jax.Array | None = None, algorithm_info: dict[str, ~typing.Any] = <factory>) None
Methods
__init__(vertices[, faces, algorithm_info])Compute axis-aligned bounding box.
centroid()Compute hull centroid (with caching).
contains(point[, tolerance])Test if point is inside hull.
diameter()Compute hull diameter (maximum distance between vertices).
distance_to(point)Compute distance from point to hull.
from_dict(data)Create ConvexHull from dictionary representation.
from_points(points[, algorithm])Create ConvexHull from point cloud.
is_degenerate([tolerance])Check if hull is degenerate (lower-dimensional).
rotate(angle[, axis])Rotate the convex hull (Phase 2 implementation).
scale(factor)Scale the convex hull (Phase 2 implementation).
summary()Get summary statistics of the hull.
Compute hull surface area (with caching).
to_dict()Convert hull to dictionary representation.
translate(vector)Translate the convex hull (Phase 2 implementation).
Get vertices as JAX array.
volume([method])Compute hull volume (with caching).
Attributes
Spatial dimension.
Number of hull vertices.
- classmethod from_points(points: Array, algorithm: str = 'approximate', **kwargs) ConvexHull[source]
Create ConvexHull from point cloud.
- Parameters:
points – Input point cloud with shape (n_points, dim)
algorithm – Hull computation algorithm (“approximate”)
**kwargs – Algorithm-specific parameters
- Returns:
ConvexHull instance
Example
>>> points = jnp.random.normal(jax.random.PRNGKey(0), (50, 3)) >>> hull = ConvexHull.from_points(points, n_directions=100)
- volume(method: str = 'simplex_decomposition') float | Array[source]
Compute hull volume (with caching).
- Parameters:
method – Volume computation method
- Returns:
Volume of the convex hull
- surface_area() float | Array[source]
Compute hull surface area (with caching).
- Returns:
Surface area of the convex hull
- contains(point: Array, tolerance: float = 1e-08) bool[source]
Test if point is inside hull.
- Parameters:
point – Point to test with shape (dim,)
tolerance – Numerical tolerance
- Returns:
True if point is inside or on boundary
- distance_to(point: Array) float[source]
Compute distance from point to hull.
- Parameters:
point – Point with shape (dim,)
- Returns:
Signed distance (positive=outside, negative=inside)
- bounding_box() tuple[Array, Array][source]
Compute axis-aligned bounding box.
- Returns:
Tuple of (min_coords, max_coords)
- diameter() float[source]
Compute hull diameter (maximum distance between vertices).
- Returns:
Maximum distance between any two vertices
- is_degenerate(tolerance: float = 1e-10) bool[source]
Check if hull is degenerate (lower-dimensional).
- Parameters:
tolerance – Tolerance for degeneracy detection
- Returns:
True if hull is degenerate
- summary() dict[str, Any][source]
Get summary statistics of the hull.
- Returns:
Dictionary containing various hull properties
- to_dict() dict[str, Any][source]
Convert hull to dictionary representation.
- Returns:
Dictionary representation suitable for serialization
- classmethod from_dict(data: dict[str, Any]) ConvexHull[source]
Create ConvexHull from dictionary representation.
- Parameters:
data – Dictionary containing hull data
- Returns:
ConvexHull instance
- scale(factor: float | Array) ConvexHull[source]
Scale the convex hull (Phase 2 implementation).
- Parameters:
factor – Scaling factor (scalar or per-dimension)
- Returns:
New scaled ConvexHull instance
- translate(vector: Array) ConvexHull[source]
Translate the convex hull (Phase 2 implementation).
- Parameters:
vector – Translation vector
- Returns:
New translated ConvexHull instance