Primitives¶
Geometric primitives inheriting from equinox.Module with SDF, parameters, and volume interface.
brepax.primitives
¶
Geometric primitives with SDF interface.
BSplineSurface
¶
Bases: Primitive
B-spline surface defined by a control point grid and knot vectors.
The SDF is computed via closest-point projection onto the surface.
Control points are differentiable design variables: jax.grad
flows through the unrolled Newton projection.
Attributes:
| Name | Type | Description |
|---|---|---|
control_points |
Float[Array, 'nu nv 3']
|
Control point grid, shape |
knots_u |
Array
|
Knot vector in u-direction. |
knots_v |
Array
|
Knot vector in v-direction. |
degree_u |
int
|
Polynomial degree in u. |
degree_v |
int
|
Polynomial degree in v. |
Examples:
>>> import jax.numpy as jnp
>>> pts = jnp.array([[[0,0,0],[1,0,0]],
... [[0,1,0],[1,1,0]]], dtype=float)
>>> knots = jnp.array([0., 0., 1., 1.])
>>> surf = BSplineSurface(
... control_points=pts, knots_u=knots, knots_v=knots,
... degree_u=1, degree_v=1,
... )
>>> d = surf.sdf(jnp.array([0.5, 0.5, 1.0]))
Source code in src/brepax/primitives/bspline_surface.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 | |
parameters()
¶
Return differentiable design parameters.
Source code in src/brepax/primitives/bspline_surface.py
sdf(x)
¶
Signed distance from query points to the B-spline surface.
For batched inputs, each point is projected independently via Newton iteration.
Source code in src/brepax/primitives/bspline_surface.py
Box
¶
Bases: Primitive
An axis-aligned box defined by center and half-extents.
Attributes:
| Name | Type | Description |
|---|---|---|
center |
Float[Array, 3]
|
Center of the box (3,). |
half_extents |
Float[Array, 3]
|
Half-size in each dimension (3,). |
Source code in src/brepax/primitives/box.py
parameters()
¶
sdf(x)
¶
Signed distance from query points to the box surface.
Source code in src/brepax/primitives/box.py
Cone
¶
Bases: Primitive
An infinite cone defined by apex position, axis direction, and half-angle.
The cone extends infinitely from the apex along the axis direction. The SDF is positive outside, negative inside.
Attributes:
| Name | Type | Description |
|---|---|---|
apex |
Float[Array, 3]
|
Apex point of the cone (3,). |
axis |
Float[Array, 3]
|
Unit direction vector from apex (3,). Must be normalized. |
angle |
Float[Array, '']
|
Half-angle in radians (0, pi/2). |
Source code in src/brepax/primitives/cone.py
parameters()
¶
sdf(x)
¶
Signed distance from query points to the cone surface.
Source code in src/brepax/primitives/cone.py
Cylinder
¶
Bases: Primitive
An infinite cylinder defined by a point on the axis, axis direction, and radius.
The SDF measures perpendicular distance from the axis line minus the radius. The cylinder extends infinitely along the axis direction.
Attributes:
| Name | Type | Description |
|---|---|---|
point |
Float[Array, 3]
|
A point on the cylinder axis (3,). |
axis |
Float[Array, 3]
|
Unit direction vector of the axis (3,). Must be normalized. |
radius |
Float[Array, '']
|
Scalar radius (must be positive). |
Source code in src/brepax/primitives/cylinder.py
parameters()
¶
sdf(x)
¶
Signed distance from query points to the cylinder surface.
Computes the perpendicular distance from each query point to the cylinder axis, then subtracts the radius.
Source code in src/brepax/primitives/cylinder.py
Disk
¶
Bases: Primitive
A 2D disk defined by center and radius.
Attributes:
| Name | Type | Description |
|---|---|---|
center |
Float[Array, 2]
|
Center coordinates (2,). |
radius |
Float[Array, '']
|
Scalar radius (must be positive). |
Source code in src/brepax/primitives/disk.py
FiniteCylinder
¶
Bases: Primitive
A finite cylinder (capped) defined by center, axis, radius, and height.
The cylinder is centered at center and extends height/2 in each
direction along axis.
Attributes:
| Name | Type | Description |
|---|---|---|
center |
Float[Array, 3]
|
Center of the cylinder (3,). |
axis |
Float[Array, 3]
|
Unit direction vector of the axis (3,). Must be normalized. |
radius |
Float[Array, '']
|
Cylinder radius (must be positive). |
height |
Float[Array, '']
|
Total height along the axis (must be positive). |
Source code in src/brepax/primitives/finite_cylinder.py
parameters()
¶
Return differentiable design parameters.
sdf(x)
¶
Signed distance from query points to the finite cylinder surface.
Source code in src/brepax/primitives/finite_cylinder.py
Plane
¶
Bases: Primitive
An infinite plane (half-space boundary) defined by normal and offset.
The SDF is positive on the side the normal points toward (outside), and negative on the opposite side (inside).
Attributes:
| Name | Type | Description |
|---|---|---|
normal |
Float[Array, 3]
|
Unit normal vector (3,). Must be normalized. |
offset |
Float[Array, '']
|
Signed distance from origin to the plane along the normal. |
Source code in src/brepax/primitives/plane.py
parameters()
¶
Primitive
¶
Bases: Module
Base class for all geometric primitives.
Each primitive exposes an SDF, gradient w.r.t. spatial coordinates, and a list of design parameters that gradients can flow into.
Source code in src/brepax/primitives/_base.py
parameters()
abstractmethod
¶
sdf(x)
abstractmethod
¶
volume()
¶
Analytical volume of this primitive.
Returns the finite volume for bounded primitives (Sphere, Box, etc.). Unbounded primitives (Cylinder, Plane, Cone) return inf. Override in subclasses with known analytical formulas. Differentiable via jax.grad for gradient computation.
Source code in src/brepax/primitives/_base.py
Sphere
¶
Bases: Primitive
A 3D sphere defined by center and radius.
Attributes:
| Name | Type | Description |
|---|---|---|
center |
Float[Array, 3]
|
Center coordinates (3,). |
radius |
Float[Array, '']
|
Scalar radius (must be positive). |
Source code in src/brepax/primitives/sphere.py
Torus
¶
Bases: Primitive
A torus defined by center, axis, major radius, and minor radius.
Attributes:
| Name | Type | Description |
|---|---|---|
center |
Float[Array, 3]
|
Center of the torus (3,). |
axis |
Float[Array, 3]
|
Unit normal to the torus plane (3,). Must be normalized. |
major_radius |
Float[Array, '']
|
Distance from center to tube center. |
minor_radius |
Float[Array, '']
|
Tube radius. |
Source code in src/brepax/primitives/torus.py
parameters()
¶
sdf(x)
¶
Signed distance from query points to the torus surface.
Source code in src/brepax/primitives/torus.py
box
¶
3D axis-aligned box primitive defined by center and half-extents.
Box
¶
Bases: Primitive
An axis-aligned box defined by center and half-extents.
Attributes:
| Name | Type | Description |
|---|---|---|
center |
Float[Array, 3]
|
Center of the box (3,). |
half_extents |
Float[Array, 3]
|
Half-size in each dimension (3,). |
Source code in src/brepax/primitives/box.py
parameters()
¶
sdf(x)
¶
Signed distance from query points to the box surface.
Source code in src/brepax/primitives/box.py
bspline_surface
¶
B-spline surface primitive with differentiable SDF.
Wraps the NURBS evaluation and closest-point projection pipeline
as a :class:~brepax.primitives.Primitive so that existing Boolean
operations and metrics work with NURBS surfaces automatically.
The surface is unbounded (a single open patch, not a closed solid),
so volume() returns infinity and Boolean operations fall back to
grid-based evaluation, matching the pattern used by
:class:~brepax.primitives.Plane and
:class:~brepax.primitives.Cylinder.
BSplineSurface
¶
Bases: Primitive
B-spline surface defined by a control point grid and knot vectors.
The SDF is computed via closest-point projection onto the surface.
Control points are differentiable design variables: jax.grad
flows through the unrolled Newton projection.
Attributes:
| Name | Type | Description |
|---|---|---|
control_points |
Float[Array, 'nu nv 3']
|
Control point grid, shape |
knots_u |
Array
|
Knot vector in u-direction. |
knots_v |
Array
|
Knot vector in v-direction. |
degree_u |
int
|
Polynomial degree in u. |
degree_v |
int
|
Polynomial degree in v. |
Examples:
>>> import jax.numpy as jnp
>>> pts = jnp.array([[[0,0,0],[1,0,0]],
... [[0,1,0],[1,1,0]]], dtype=float)
>>> knots = jnp.array([0., 0., 1., 1.])
>>> surf = BSplineSurface(
... control_points=pts, knots_u=knots, knots_v=knots,
... degree_u=1, degree_v=1,
... )
>>> d = surf.sdf(jnp.array([0.5, 0.5, 1.0]))
Source code in src/brepax/primitives/bspline_surface.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 | |
parameters()
¶
Return differentiable design parameters.
Source code in src/brepax/primitives/bspline_surface.py
sdf(x)
¶
Signed distance from query points to the B-spline surface.
For batched inputs, each point is projected independently via Newton iteration.
Source code in src/brepax/primitives/bspline_surface.py
cone
¶
3D infinite cone primitive defined by apex, axis, and half-angle.
Cone
¶
Bases: Primitive
An infinite cone defined by apex position, axis direction, and half-angle.
The cone extends infinitely from the apex along the axis direction. The SDF is positive outside, negative inside.
Attributes:
| Name | Type | Description |
|---|---|---|
apex |
Float[Array, 3]
|
Apex point of the cone (3,). |
axis |
Float[Array, 3]
|
Unit direction vector from apex (3,). Must be normalized. |
angle |
Float[Array, '']
|
Half-angle in radians (0, pi/2). |
Source code in src/brepax/primitives/cone.py
parameters()
¶
sdf(x)
¶
Signed distance from query points to the cone surface.
Source code in src/brepax/primitives/cone.py
cylinder
¶
3D infinite cylinder primitive defined by axis, point on axis, and radius.
Cylinder
¶
Bases: Primitive
An infinite cylinder defined by a point on the axis, axis direction, and radius.
The SDF measures perpendicular distance from the axis line minus the radius. The cylinder extends infinitely along the axis direction.
Attributes:
| Name | Type | Description |
|---|---|---|
point |
Float[Array, 3]
|
A point on the cylinder axis (3,). |
axis |
Float[Array, 3]
|
Unit direction vector of the axis (3,). Must be normalized. |
radius |
Float[Array, '']
|
Scalar radius (must be positive). |
Source code in src/brepax/primitives/cylinder.py
parameters()
¶
sdf(x)
¶
Signed distance from query points to the cylinder surface.
Computes the perpendicular distance from each query point to the cylinder axis, then subtracts the radius.
Source code in src/brepax/primitives/cylinder.py
disk
¶
2D disk primitive defined by center and radius.
Disk
¶
Bases: Primitive
A 2D disk defined by center and radius.
Attributes:
| Name | Type | Description |
|---|---|---|
center |
Float[Array, 2]
|
Center coordinates (2,). |
radius |
Float[Array, '']
|
Scalar radius (must be positive). |
Source code in src/brepax/primitives/disk.py
finite_cylinder
¶
3D finite cylinder primitive defined by center, axis, radius, and height.
FiniteCylinder
¶
Bases: Primitive
A finite cylinder (capped) defined by center, axis, radius, and height.
The cylinder is centered at center and extends height/2 in each
direction along axis.
Attributes:
| Name | Type | Description |
|---|---|---|
center |
Float[Array, 3]
|
Center of the cylinder (3,). |
axis |
Float[Array, 3]
|
Unit direction vector of the axis (3,). Must be normalized. |
radius |
Float[Array, '']
|
Cylinder radius (must be positive). |
height |
Float[Array, '']
|
Total height along the axis (must be positive). |
Source code in src/brepax/primitives/finite_cylinder.py
parameters()
¶
Return differentiable design parameters.
sdf(x)
¶
Signed distance from query points to the finite cylinder surface.
Source code in src/brepax/primitives/finite_cylinder.py
foot
¶
Analytical foot-of-perpendicular on primitive surfaces.
Each function returns the closest point on an infinite analytical surface (plane, sphere, cylinder, cone, torus) to a query point. Closed form given the primitive parameters; fully differentiable w.r.t. both the query and the primitive parameters.
Scope is the untrimmed surface only; trim-boundary interaction is layered on via Marschner composition in a separate module. Cone and torus inner-region degeneracies (apex, tube axis) are handled with an epsilon guard on the radial direction.
Zero-denominator handling uses a safe-square-then-sqrt pattern that
keeps both forward and gradient finite at the degenerate boundary.
jnp.linalg.norm(v) has infinite derivative at v = 0; since
jnp.where evaluates both branches in the VJP, a naive guard on
norm still leaks NaN into jax.grad. The pattern used here
switches on the squared norm before sqrt, so the sqrt argument
is bounded below by 1 when the query is degenerate:
sq = sum(v * v)
is_ok = sq > eps_sq
safe_sq = where(is_ok, sq, 1.0)
norm = sqrt(safe_sq) # always >= 1 at the degenerate point
direction = where(is_ok, v / norm, fallback)
foot_on_cone(query, apex, axis, angle)
¶
Closest point on the half-cone extending forward of apex.
The cone is the surface r(h) = h * tan(angle) for h >= 0
along axis. For queries that project to h < 0 the foot is
clamped to apex.
Source code in src/brepax/primitives/foot.py
foot_on_cylinder(query, point, axis, radius)
¶
Closest point on an infinite cylinder of radius about the axis.
On the axis itself the radial direction is ill-defined; a canonical
unit vector orthogonal to axis is used to keep the computation
differentiable.
Source code in src/brepax/primitives/foot.py
foot_on_plane(query, normal, offset)
¶
Closest point on an infinite plane normal . x = offset.
Source code in src/brepax/primitives/foot.py
foot_on_sphere(query, center, radius)
¶
Closest point on a sphere of radius around center.
At the center (degenerate) the result is center + radius * e_z;
an arbitrary direction is required to keep the gradient finite.
Source code in src/brepax/primitives/foot.py
foot_on_torus(query, center, axis, major_radius, minor_radius)
¶
Closest point on the torus tube around the major ring.
Project to the tube-center ring first, then shift outward by
minor_radius. On the central axis (radial == 0) a canonical
in-plane direction is used; on the tube center itself
(dq == 0) the fallback is the radial direction.
Source code in src/brepax/primitives/foot.py
plane
¶
3D plane primitive defined by normal vector and offset.
Plane
¶
Bases: Primitive
An infinite plane (half-space boundary) defined by normal and offset.
The SDF is positive on the side the normal points toward (outside), and negative on the opposite side (inside).
Attributes:
| Name | Type | Description |
|---|---|---|
normal |
Float[Array, 3]
|
Unit normal vector (3,). Must be normalized. |
offset |
Float[Array, '']
|
Signed distance from origin to the plane along the normal. |
Source code in src/brepax/primitives/plane.py
parameters()
¶
sphere
¶
3D sphere primitive defined by center and radius.
Sphere
¶
Bases: Primitive
A 3D sphere defined by center and radius.
Attributes:
| Name | Type | Description |
|---|---|---|
center |
Float[Array, 3]
|
Center coordinates (3,). |
radius |
Float[Array, '']
|
Scalar radius (must be positive). |
Source code in src/brepax/primitives/sphere.py
torus
¶
3D torus primitive defined by center, axis, major radius, and minor radius.
Torus
¶
Bases: Primitive
A torus defined by center, axis, major radius, and minor radius.
Attributes:
| Name | Type | Description |
|---|---|---|
center |
Float[Array, 3]
|
Center of the torus (3,). |
axis |
Float[Array, 3]
|
Unit normal to the torus plane (3,). Must be normalized. |
major_radius |
Float[Array, '']
|
Distance from center to tube center. |
minor_radius |
Float[Array, '']
|
Tube radius. |
Source code in src/brepax/primitives/torus.py
parameters()
¶
sdf(x)
¶
Signed distance from query points to the torus surface.