geoclide.intersection module#

Standardized ray-shape intersection tests.

This module provides the calc_intersection function, which performs the intersection test between any geoclide shape (BBox, Sphere, Spheroid, Disk, Triangle or TriangleMesh) and a ray or a set of rays, and returns an xarray dataset gathering the intersection results together with the shape attributes.

geoclide.intersection.calc_intersection(shape: BBox | Sphere | Spheroid | Disk | Triangle | TriangleMesh, r: Ray, **kwargs) Dataset[source]#

Performs intersection test between a shape and a ray and returns dataset

Parameters:
shapeBBox, Sphere, Spheroid, Disk, Triangle or TriangleMesh

The shape used for the intersection(s)

rRay

The ray(s) used for the intersection(s)

**kwargs

The keyword arguments are passed on to intersect method. The ds_output parameter is forced here to always be True.

Returns:
Dataset

Xarray dataset containing the intersection information.

Key variables included:

  • o: The origin(s) of the ray(s) [xyz]

  • d: The direction(s) of the ray(s) [xyz]

  • mint: The mint attribute of the ray(s)

  • maxt: The maxt attribute of the ray(s)

  • is_intersection: If there is an intersection -> True, else False

  • thit: The t ray variable(s) of the intersection point(s)

  • phit: The intersection point(s) [xyz]

  • nhit: The surface normal(s) at the intersection point(s) [xyz] (not for a BBox)

  • u, v, dpdu, dpdv: The parametric coordinates and surface partial derivatives (not for a BBox)

  • the shape attributes (e.g. radius, z_min, z_max and phi_max for a sphere, or pmin and pmax for a bounding box)

  • wto_m, wto_m_inv, otw_m, otw_m_inv: The transformation matrices of the shape (not for a BBox)

Examples

>>> import geoclide as gc
>>> sphere = gc.Sphere(radius=1.) # sphere of radius 1
>>> bbox = gc.BBox(p1=gc.Point(0., 0., 0.), p2=gc.Point(1.,1.,1.))
>>> ray = gc.Ray(o=gc.Point(-2., 0., 0.8), d=gc.Vector(1.,0.,0.))
>>> ds_sphere = gc.calc_intersection(sphere, ray)
>>> ds_sphere['thit'].values
array(1.4)
>>> ds_sphere['phit'].values
array([-0.6,  0. ,  0.8])
>>> ds_bbox = gc.calc_intersection(bbox, ray)
>>> ds_bbox['thit'].values
array(2.)
>>> ds_bbox['phit'].values
array([0. , 0. , 0.8])