Applications¶
Experimental application demonstrators built on BRepAX primitives and Boolean operations.
brepax.experimental.applications
¶
Experimental application demonstrations.
Showcases built on top of BRepAX primitives and Boolean operations. APIs here are subject to change without notice.
MoldDirectionResult
dataclass
¶
Result of mold direction optimization.
Attributes:
| Name | Type | Description |
|---|---|---|
direction |
Float[Array, 3]
|
Optimized pull direction (unit vector). |
trajectory |
Float[Array, 'n 3']
|
Direction at each step, shape (steps+1, 3). |
losses |
list[float]
|
Undercut volume at each step. |
converged |
bool
|
Whether loss change dropped below tolerance. |
Source code in src/brepax/experimental/applications/mold_direction.py
optimize_mold_direction(shape_sdf, initial_direction, *, lo, hi, resolution=64, steps=100, lr=0.01, tol=1e-06)
¶
Find the mold pull direction that minimizes undercut volume.
Uses projected gradient descent on S^2: after each gradient step the direction vector is re-normalized to the unit sphere.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
shape_sdf
|
Callable[[Float[Array, 3]], Float[Array, '']]
|
Signed distance function for a single query point. |
required |
initial_direction
|
Float[Array, 3]
|
Starting pull direction (will be normalized). |
required |
lo
|
Float[Array, 3]
|
Lower corner of the evaluation domain. |
required |
hi
|
Float[Array, 3]
|
Upper corner of the evaluation domain. |
required |
resolution
|
int
|
Grid resolution per axis. |
64
|
steps
|
int
|
Maximum optimization steps. |
100
|
lr
|
float
|
Learning rate for gradient descent. |
0.01
|
tol
|
float
|
Convergence tolerance on absolute loss change. |
1e-06
|
Returns:
| Type | Description |
|---|---|
MoldDirectionResult
|
MoldDirectionResult with optimized direction and diagnostics. |
Examples:
>>> import jax.numpy as jnp
>>> from brepax.primitives import Box
>>> box = Box(
... center=jnp.array([0.0, 0.0, 0.0]),
... half_extents=jnp.array([1.0, 1.0, 0.5]),
... )
>>> result = optimize_mold_direction(
... box.sdf,
... jnp.array([1.0, 1.0, 1.0]),
... lo=jnp.array([-2.0, -2.0, -2.0]),
... hi=jnp.array([2.0, 2.0, 2.0]),
... resolution=32,
... steps=50,
... )
Source code in src/brepax/experimental/applications/mold_direction.py
undercut_volume(shape_sdf, direction, *, lo, hi, resolution=64)
¶
Estimate undercut volume for a mold pull direction.
Undercut is defined as the set of interior points whose SDF spatial gradient (outward normal) opposes the pull direction. Both the interior membership and the undercut condition are smoothed with sigmoid indicators scaled by the grid cell width, ensuring the estimate improves with resolution.
Normals are estimated via central finite differences to avoid NaN gradients at degenerate SDF points (cylinder axis, box center, etc.).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
shape_sdf
|
Callable[[Float[Array, 3]], Float[Array, '']]
|
Signed distance function for a single query point. Must accept shape (3,) and return scalar. |
required |
direction
|
Float[Array, 3]
|
Unit pull direction on S^2. |
required |
lo
|
Float[Array, 3]
|
Lower corner of the evaluation domain. |
required |
hi
|
Float[Array, 3]
|
Upper corner of the evaluation domain. |
required |
resolution
|
int
|
Grid resolution per axis. |
64
|
Returns:
| Type | Description |
|---|---|
Float[Array, '']
|
Scalar estimated undercut volume. |
Examples:
>>> import jax.numpy as jnp
>>> from brepax.primitives import Box
>>> box = Box(
... center=jnp.array([0.0, 0.0, 0.0]),
... half_extents=jnp.array([1.0, 1.0, 0.5]),
... )
>>> vol = undercut_volume(
... box.sdf,
... jnp.array([0.0, 0.0, 1.0]),
... lo=jnp.array([-2.0, -2.0, -2.0]),
... hi=jnp.array([2.0, 2.0, 2.0]),
... resolution=32,
... )
Source code in src/brepax/experimental/applications/mold_direction.py
mold_direction
¶
Mold pull-direction optimization via differentiable undercut analysis.
Given a shape defined by its SDF, estimates the volume of material that would prevent mold removal in a given pull direction. The undercut criterion is SDF-based: a surface point is undercut when its outward normal opposes the pull direction (dot(normal, direction) < 0).
Both the undercut volume and the optimization loop are fully differentiable, enabling gradient-based search over the unit sphere S^2.
MoldDirectionResult
dataclass
¶
Result of mold direction optimization.
Attributes:
| Name | Type | Description |
|---|---|---|
direction |
Float[Array, 3]
|
Optimized pull direction (unit vector). |
trajectory |
Float[Array, 'n 3']
|
Direction at each step, shape (steps+1, 3). |
losses |
list[float]
|
Undercut volume at each step. |
converged |
bool
|
Whether loss change dropped below tolerance. |
Source code in src/brepax/experimental/applications/mold_direction.py
optimize_mold_direction(shape_sdf, initial_direction, *, lo, hi, resolution=64, steps=100, lr=0.01, tol=1e-06)
¶
Find the mold pull direction that minimizes undercut volume.
Uses projected gradient descent on S^2: after each gradient step the direction vector is re-normalized to the unit sphere.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
shape_sdf
|
Callable[[Float[Array, 3]], Float[Array, '']]
|
Signed distance function for a single query point. |
required |
initial_direction
|
Float[Array, 3]
|
Starting pull direction (will be normalized). |
required |
lo
|
Float[Array, 3]
|
Lower corner of the evaluation domain. |
required |
hi
|
Float[Array, 3]
|
Upper corner of the evaluation domain. |
required |
resolution
|
int
|
Grid resolution per axis. |
64
|
steps
|
int
|
Maximum optimization steps. |
100
|
lr
|
float
|
Learning rate for gradient descent. |
0.01
|
tol
|
float
|
Convergence tolerance on absolute loss change. |
1e-06
|
Returns:
| Type | Description |
|---|---|
MoldDirectionResult
|
MoldDirectionResult with optimized direction and diagnostics. |
Examples:
>>> import jax.numpy as jnp
>>> from brepax.primitives import Box
>>> box = Box(
... center=jnp.array([0.0, 0.0, 0.0]),
... half_extents=jnp.array([1.0, 1.0, 0.5]),
... )
>>> result = optimize_mold_direction(
... box.sdf,
... jnp.array([1.0, 1.0, 1.0]),
... lo=jnp.array([-2.0, -2.0, -2.0]),
... hi=jnp.array([2.0, 2.0, 2.0]),
... resolution=32,
... steps=50,
... )
Source code in src/brepax/experimental/applications/mold_direction.py
undercut_volume(shape_sdf, direction, *, lo, hi, resolution=64)
¶
Estimate undercut volume for a mold pull direction.
Undercut is defined as the set of interior points whose SDF spatial gradient (outward normal) opposes the pull direction. Both the interior membership and the undercut condition are smoothed with sigmoid indicators scaled by the grid cell width, ensuring the estimate improves with resolution.
Normals are estimated via central finite differences to avoid NaN gradients at degenerate SDF points (cylinder axis, box center, etc.).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
shape_sdf
|
Callable[[Float[Array, 3]], Float[Array, '']]
|
Signed distance function for a single query point. Must accept shape (3,) and return scalar. |
required |
direction
|
Float[Array, 3]
|
Unit pull direction on S^2. |
required |
lo
|
Float[Array, 3]
|
Lower corner of the evaluation domain. |
required |
hi
|
Float[Array, 3]
|
Upper corner of the evaluation domain. |
required |
resolution
|
int
|
Grid resolution per axis. |
64
|
Returns:
| Type | Description |
|---|---|
Float[Array, '']
|
Scalar estimated undercut volume. |
Examples:
>>> import jax.numpy as jnp
>>> from brepax.primitives import Box
>>> box = Box(
... center=jnp.array([0.0, 0.0, 0.0]),
... half_extents=jnp.array([1.0, 1.0, 0.5]),
... )
>>> vol = undercut_volume(
... box.sdf,
... jnp.array([0.0, 0.0, 1.0]),
... lo=jnp.array([-2.0, -2.0, -2.0]),
... hi=jnp.array([2.0, 2.0, 2.0]),
... resolution=32,
... )