When performing spacecraft simulations, developers sometimes need to feed the simulation with a distance between two objects along a certain direction vector. For example, if a spacecraft is approaching an asteroid and needs to simulate a laser rangefinder, the simulation would need to detect what part of the asteroid the laser would intersect, and then calculate the distance from the rangefinder to the surface. For an asteroid with a very complex geometry, the search for the intersecting triangle can be very costly in terms of compute time. This scenario presented itself with the MMSEV spacecraft simulation approaching the asteroid “Itokawa.”

RAYGUN is a standalone utility as well as a development library that can be used in other programs, and that performs a time-optimized raycast against a generic geometry definition described by a list of triangles. Two vectors, supplied as inputs to the library, provide the origin and the direction of the ray. Also, a file is provided that gives the entire triangle list against which to be searched. After processing the inputs, the code will then generate a bounding volume hierarchy to sort the triangles for quick searching. The specific hierarchy used at the moment is known as an “octree,” but the code can be extended to use other hierarchies as well.

Once the hierarchy has been generated into memory, raycasts can be performed very quickly using any ray origin and ray direction as the inputs. Also, a special cache file of the hierarchy can be saved to disk to avoid having to construct a hierarchy for future runs that use the same geometry to be tested.

In practice, this utility can be run on the command line with a geometry definition filename (or cache from a previous run); the ray origin X,Y,Z; and the ray direction X,Y,Z. When used as a library, the code can very easily be included into an existing C or C++ program, or compiled into a shared library that can be linked into an existing program. One advantage is that this software does not have any major software dependencies. It is written in pure C without the need for any external libraries, and therefore can be used by developers who want to pull in a raycasting solution without dependencies on other software.

This work was done by Frank Graffagnino of Metecs for Johnson Space Center. This software is available for use. To request a copy, please visit here .

NASA Tech Briefs Magazine

This article first appeared in the May, 2017 issue of NASA Tech Briefs Magazine.

Read more articles from this issue here.

Read more articles from the archives here.