Skip to content

Surface projection ​

Surface projection turns an unstructured body surface into a structured array of surface nodes. Rays leave one anchor point inside the body along a structured set of directions; each ray's hit on the body is a k=0 node. The projector knows nothing about blocks: the k=0 construction decides which directions to cast.

Rays from the anchor inside a star-shaped section; each first hit on the body becomes a k=0 node.Rays from the anchor inside a star-shaped section; each first hit on the body becomes a k=0 node.
Rays from the anchor inside a star-shaped section; each first hit on the body becomes a k=0 node.

Inputs and outputs ​

Inputthe body, an anchor point inside it, and unit directions of shape (N, 3)
OutputProjectionResult: locations (N, 3) (NaN where a ray failed), status per ray, distances from the anchor
Codeshore.surface.projector.Projector (STL); AnchoredCaster for CAD bodies

Anchor ​

All rays share one origin, so the body must be star-shaped from the anchor: every ray must cross the surface exactly once. resolve_anchor picks the anchor; Body.from_stl / Body.from_file use the auto strategy:

StrategyAnchor
auto (default)incenter, else bbox, each validated; raises if both fail
incentercentre of the minimum enclosing sphere of the vertices
bboxbounding-box centre
centroidvolumetric centroid (can lie outside a non-convex body)
usera given point, validated

Validation is a mesh.contains test. A body whose anchor cannot be resolved still loads: the error is kept and raised when the projector is first used, so open half-model bodies can still serve collar grids (ADR 0018).

Ray casting ​

For an STL the Projector builds a trimesh BVH (RayMeshIntersector) once per body and reuses it for every call, so a batch costs one vectorised query. Each hit is classified, in this priority:

StatusCondition
DEGENERATENaN in the hit
BACKFACEthe hit triangle's normal does not face along the ray (inverted or wrong-side facet)
TOO_NEARhit closer than 5 % of the body's bounding-box diagonal
TOO_FARhit farther than 5 bounding-box diagonals
MISSEDno hit
HITeverything else

Only the first hit along each ray is kept. project(dirs, on_failure=...) decides what a non-HIT ray does: "raise" (default, MeshInputError with the counts per status), "nearest" (fall back to the closest surface point and keep the status flag) or "skip" (leave NaN).

For a CAD body the caster ray-casts the merged tessellation and then snaps every hit to the exact surface, so the k=0 nodes lie on the CAD faces, not on the facets (ADR 0002).

Who supplies the directions ​

  • Cubed sphere: build_cap_k0 casts a gnomonic diamond at each pole, then build_equator casts slerped great-circle meridians between the two cap seam rings; the seam rows are copied from the caps, not re-cast (k=0 construction).
  • O-grid: sphere_latlon_directions builds a lat-lon grid of directions over colatitudes [θcap,π−θcap], cast in one batch.
  • OH hybrid: the cubed-sphere directions with theta_cap and the azimuth offset both pinned to π/4.

Failure modes ​

SymptomCause
MeshInputError naming the anchoranchor outside the body: the body is not closed, or not star-shaped from any of the tried points
MeshInputError with missed / backface countssome rays leave through a gap, or hit an inverted facet; repair the STL
several hits along a ray, only the first keptthe body is not star-shaped from the anchor: the grid skips the hidden surface; nothing warns, so inspect the k=0 layer

For bodies that cannot be star-shaped, see Pipeline limits.

See also ​

Released under the MIT License.