# Proximity Toolkit Collision Detection

The Proximity Toolkit comes with basic built-in functionality for representing spatial objects in 3D space. This functionality is available in the *ProximityToolkit.Collision* namespace.

The available objects inherit from CollisionBase, and represent geometry as follows:

**Box**- a 3D box with 6 sides (represented as Squares)**Line**- a 1D object that spans infinitely in both directions.**LineSegment**- a 1D object that spans from one end point to the other.**Plane**- a 2D object that spans infinitely.**Point**- a 0D object that represents a single point in space.**Ray**- a 1D object that has a starting point, and spans infinitely in a particular direction.**Sphere**- a 3D volume that can radiate uniformly from a center point (a sphere) or in different proportions (an elliptoid).**Square**- a Plane bounded by four corners.

A special object called the **CollisionComposite** represents the union of any number of the above objects, and can be collided as an object itself.

Collision information can be calculated between any combination of these objects. This is done by declaring a new instance of the **CollisionDetails** object and providing the two objects to test for collision to the constructor. The CollisionDetails object contains all collision calculation methods for the various combinations of objects, and automatically selects whichever one is appropriate.

The CollisionDetails object has the following properties that provide information about the collision:

- bool
*Collides*- Whether or not a collision was detected. - bool
*Contains*- Whether or not one object completely encompasses the other. - Vector3
*IntersectPoint*- A single point representing the intersection. - Vector3
*NearestPoint*- A single point representing the closest possible point of intersection. When a collision occurs, this equals IntersectPoint. Otherwise, when no collision occurs, this is the best estimation, when available. - double
*Distance*- When no collision occurs, this is the best estimation of the shortest distance between the two objects. When a collision does occur, this value is 0. - ICollidible
*IntersectVolume*- A collision volume that represents the area of overlap of the two colliding objects. **WARNING** Only return values of Point and Line/LineSegment/Ray are currently supported.

## Following Subjects

The **TrackedPresences** class has a property called *ModelCollisionVolume* which allows you to set the collision volume for the subject. **Note that currently, no default collision object is provided - it is entirely up to the programmer to specify this volume.** You must specify this volume even for the Collision relation to work properly.

The position and orientation of this volume is automatically updated to follow the actual position and orientation of the subject. The *CollisionObject* property returns the transformed clone of the original collision volume set with *ModelCollisionVolume*.

Advanced programmers can manually make an object follow your subject as follows:
`CollisionBase transformedobj = originalobj.Clone( subject.LocalTransform );`