Class Collision
- Namespace
- HelixToolkit.Maths
- Assembly
- HelixToolkit.Maths.dll
Contains static methods to help in determining intersections, containment, etc.
public static class Collision
- Inheritance
-
Collision
- Inherited Members
Methods
BoxContainsBox(ref BoundingBox, ref BoundingBox)
Determines whether a BoundingBox contains a BoundingBox.
public static ContainmentType BoxContainsBox(ref BoundingBox box1, ref BoundingBox box2)
Parameters
box1BoundingBoxThe first box to test.
box2BoundingBoxThe second box to test.
Returns
- ContainmentType
The type of containment the two objects have.
BoxContainsPoint(ref BoundingBox, ref Vector3)
Determines whether a BoundingBox contains a point.
public static ContainmentType BoxContainsPoint(ref BoundingBox box, ref Vector3 point)
Parameters
boxBoundingBoxThe box to test.
pointVector3The point to test.
Returns
- ContainmentType
The type of containment the two objects have.
BoxContainsSphere(ref BoundingBox, ref BoundingSphere)
Determines whether a BoundingBox contains a BoundingSphere.
public static ContainmentType BoxContainsSphere(ref BoundingBox box, ref BoundingSphere sphere)
Parameters
boxBoundingBoxThe box to test.
sphereBoundingSphereThe sphere to test.
Returns
- ContainmentType
The type of containment the two objects have.
BoxIntersectsBox(ref BoundingBox, ref BoundingBox)
Determines whether there is an intersection between a BoundingBox and a BoundingBox.
public static bool BoxIntersectsBox(ref BoundingBox box1, ref BoundingBox box2)
Parameters
box1BoundingBoxThe first box to test.
box2BoundingBoxThe second box to test.
Returns
- bool
Whether the two objects intersected.
BoxIntersectsSphere(ref BoundingBox, ref BoundingSphere)
Determines whether there is an intersection between a BoundingBox and a BoundingSphere.
public static bool BoxIntersectsSphere(ref BoundingBox box, ref BoundingSphere sphere)
Parameters
boxBoundingBoxThe box to test.
sphereBoundingSphereThe sphere to test.
Returns
- bool
Whether the two objects intersected.
ClosestPointBoxPoint(ref BoundingBox, ref Vector3, out Vector3)
Determines the closest point between a BoundingBox and a point.
public static void ClosestPointBoxPoint(ref BoundingBox box, ref Vector3 point, out Vector3 result)
Parameters
boxBoundingBoxThe box to test.
pointVector3The point to test.
resultVector3When the method completes, contains the closest point between the two objects.
ClosestPointPlanePoint(ref Plane, ref Vector3, out Vector3)
Determines the closest point between a Plane and a point.
public static void ClosestPointPlanePoint(ref Plane plane, ref Vector3 point, out Vector3 result)
Parameters
planePlaneThe plane to test.
pointVector3The point to test.
resultVector3When the method completes, contains the closest point between the two objects.
ClosestPointPointTriangle(ref Vector3, ref Vector3, ref Vector3, ref Vector3, out Vector3)
Determines the closest point between a point and a triangle.
public static void ClosestPointPointTriangle(ref Vector3 point, ref Vector3 vertex1, ref Vector3 vertex2, ref Vector3 vertex3, out Vector3 result)
Parameters
pointVector3The point to test.
vertex1Vector3The first vertex to test.
vertex2Vector3The second vertex to test.
vertex3Vector3The third vertex to test.
resultVector3When the method completes, contains the closest point between the two objects.
ClosestPointSpherePoint(ref BoundingSphere, ref Vector3, out Vector3)
Determines the closest point between a BoundingSphere and a point.
public static void ClosestPointSpherePoint(ref BoundingSphere sphere, ref Vector3 point, out Vector3 result)
Parameters
sphereBoundingSpherepointVector3The point to test.
resultVector3When the method completes, contains the closest point between the two objects; or, if the point is directly in the center of the sphere, contains Zero.
ClosestPointSphereSphere(ref BoundingSphere, ref BoundingSphere, out Vector3)
Determines the closest point between a BoundingSphere and a BoundingSphere.
public static void ClosestPointSphereSphere(ref BoundingSphere sphere1, ref BoundingSphere sphere2, out Vector3 result)
Parameters
sphere1BoundingSphereThe first sphere to test.
sphere2BoundingSphereThe second sphere to test.
resultVector3When the method completes, contains the closest point between the two objects; or, if the point is directly in the center of the sphere, contains Zero.
Remarks
If the two spheres are overlapping, but not directly on top of each other, the closest point is the 'closest' point of intersection. This can also be considered is the deepest point of intersection.
DistanceBoxBox(ref BoundingBox, ref BoundingBox)
Determines the distance between a BoundingBox and a BoundingBox.
public static float DistanceBoxBox(ref BoundingBox box1, ref BoundingBox box2)
Parameters
box1BoundingBoxThe first box to test.
box2BoundingBoxThe second box to test.
Returns
- float
The distance between the two objects.
DistanceBoxPoint(ref BoundingBox, ref Vector3)
Determines the distance between a BoundingBox and a point.
public static float DistanceBoxPoint(ref BoundingBox box, ref Vector3 point)
Parameters
boxBoundingBoxThe box to test.
pointVector3The point to test.
Returns
- float
The distance between the two objects.
DistancePlanePoint(ref Plane, ref Vector3)
Determines the distance between a Plane and a point.
public static float DistancePlanePoint(ref Plane plane, ref Vector3 point)
Parameters
Returns
- float
The distance between the two objects.
DistanceSpherePoint(ref BoundingSphere, ref Vector3)
Determines the distance between a BoundingSphere and a point.
public static float DistanceSpherePoint(ref BoundingSphere sphere, ref Vector3 point)
Parameters
sphereBoundingSphereThe sphere to test.
pointVector3The point to test.
Returns
- float
The distance between the two objects.
DistanceSphereSphere(ref BoundingSphere, ref BoundingSphere)
Determines the distance between a BoundingSphere and a BoundingSphere.
public static float DistanceSphereSphere(ref BoundingSphere sphere1, ref BoundingSphere sphere2)
Parameters
sphere1BoundingSphereThe first sphere to test.
sphere2BoundingSphereThe second sphere to test.
Returns
- float
The distance between the two objects.
PlaneIntersectsBox(ref Plane, ref BoundingBox)
Determines whether there is an intersection between a Plane and a BoundingBox.
public static PlaneIntersectionType PlaneIntersectsBox(ref Plane plane, ref BoundingBox box)
Parameters
planePlaneThe plane to test.
boxBoundingBoxThe box to test.
Returns
- PlaneIntersectionType
Whether the two objects intersected.
PlaneIntersectsPlane(ref Plane, ref Plane)
public static bool PlaneIntersectsPlane(ref Plane plane1, ref Plane plane2)
Parameters
Returns
- bool
Whether the two objects intersected.
PlaneIntersectsPlane(ref Plane, ref Plane, out Ray)
public static bool PlaneIntersectsPlane(ref Plane plane1, ref Plane plane2, out Ray line)
Parameters
plane1PlaneThe first plane to test.
plane2PlaneThe second plane to test.
lineRayWhen the method completes, contains the line of intersection as a Ray, or a zero ray if there was no intersection.
Returns
- bool
Whether the two objects intersected.
Remarks
Although a ray is set to have an origin, the ray returned by this method is really a line in three dimensions which has no real origin. The ray is considered valid when both the positive direction is used and when the negative direction is used.
PlaneIntersectsPoint(ref Plane, ref Vector3)
Determines whether there is an intersection between a Plane and a point.
public static PlaneIntersectionType PlaneIntersectsPoint(ref Plane plane, ref Vector3 point)
Parameters
Returns
- PlaneIntersectionType
Whether the two objects intersected.
PlaneIntersectsSphere(ref Plane, ref BoundingSphere)
Determines whether there is an intersection between a Plane and a BoundingSphere.
public static PlaneIntersectionType PlaneIntersectsSphere(ref Plane plane, ref BoundingSphere sphere)
Parameters
planePlaneThe plane to test.
sphereBoundingSphereThe sphere to test.
Returns
- PlaneIntersectionType
Whether the two objects intersected.
PlaneIntersectsTriangle(ref Plane, ref Vector3, ref Vector3, ref Vector3)
Determines whether there is an intersection between a Plane and a triangle.
public static PlaneIntersectionType PlaneIntersectsTriangle(ref Plane plane, ref Vector3 vertex1, ref Vector3 vertex2, ref Vector3 vertex3)
Parameters
planePlaneThe plane to test.
vertex1Vector3The first vertex of the triangle to test.
vertex2Vector3The second vertex of the triangle to test.
vertex3Vector3The third vertex of the triangle to test.
Returns
- PlaneIntersectionType
Whether the two objects intersected.
RayIntersectsBox(ref Ray, ref BoundingBox, out Vector3)
public static bool RayIntersectsBox(ref Ray ray, ref BoundingBox box, out Vector3 point)
Parameters
rayRayThe ray to test.
boxBoundingBoxThe box to test.
pointVector3When the method completes, contains the point of intersection, or Zero if there was no intersection.
Returns
- bool
Whether the two objects intersected.
RayIntersectsBox(ref Ray, ref BoundingBox, out float)
Determines whether there is an intersection between a Ray and a BoundingBox.
public static bool RayIntersectsBox(ref Ray ray, ref BoundingBox box, out float distance)
Parameters
rayRayThe ray to test.
boxBoundingBoxThe box to test.
distancefloatWhen the method completes, contains the distance of the intersection, or 0 if there was no intersection.
Returns
- bool
Whether the two objects intersected.
RayIntersectsPlane(ref Ray, ref Plane, out Vector3)
public static bool RayIntersectsPlane(ref Ray ray, ref Plane plane, out Vector3 point)
Parameters
rayRayThe ray to test.
planePlaneThe plane to test
pointVector3When the method completes, contains the point of intersection, or Zero if there was no intersection.
Returns
- bool
Whether the two objects intersected.
RayIntersectsPlane(ref Ray, ref Plane, out float)
public static bool RayIntersectsPlane(ref Ray ray, ref Plane plane, out float distance)
Parameters
rayRayThe ray to test.
planePlaneThe plane to test.
distancefloatWhen the method completes, contains the distance of the intersection, or 0 if there was no intersection.
Returns
- bool
Whether the two objects intersect.
RayIntersectsPoint(ref Ray, ref Vector3)
Determines whether there is an intersection between a Ray and a point.
public static bool RayIntersectsPoint(ref Ray ray, ref Vector3 point)
Parameters
Returns
- bool
Whether the two objects intersect.
RayIntersectsRay(ref Ray, ref Ray, out Vector3)
public static bool RayIntersectsRay(ref Ray ray1, ref Ray ray2, out Vector3 point)
Parameters
ray1RayThe first ray to test.
ray2RayThe second ray to test.
pointVector3When the method completes, contains the point of intersection, or Zero if there was no intersection.
Returns
- bool
Whether the two objects intersect.
Remarks
This method performs a ray vs ray intersection test based on the following formula from Goldman.
s = det([o_2 - o_1, d_2, d_1 x d_2]) / ||d_1 x d_2||^2
t = det([o_2 - o_1, d_1, d_1 x d_2]) / ||d_1 x d_2||^2
Where o_1 is the position of the first ray, o_2 is the position of the second ray, d_1 is the normalized direction of the first ray, d_2 is the normalized direction of the second ray, det denotes the determinant of a matrix, x denotes the cross product, [ ] denotes a matrix, and || || denotes the length or magnitude of a vector.
RayIntersectsSphere(ref Ray, ref BoundingSphere, out Vector3)
Determines whether there is an intersection between a Ray and a BoundingSphere.
public static bool RayIntersectsSphere(ref Ray ray, ref BoundingSphere sphere, out Vector3 point)
Parameters
rayRayThe ray to test.
sphereBoundingSphereThe sphere to test.
pointVector3When the method completes, contains the point of intersection, or Zero if there was no intersection.
Returns
- bool
Whether the two objects intersected.
RayIntersectsSphere(ref Ray, ref BoundingSphere, out float)
Determines whether there is an intersection between a Ray and a BoundingSphere.
public static bool RayIntersectsSphere(ref Ray ray, ref BoundingSphere sphere, out float distance)
Parameters
rayRayThe ray to test.
sphereBoundingSphereThe sphere to test.
distancefloatWhen the method completes, contains the distance of the intersection, or 0 if there was no intersection.
Returns
- bool
Whether the two objects intersected.
RayIntersectsTriangle(ref Ray, ref Vector3, ref Vector3, ref Vector3, out Vector3)
Determines whether there is an intersection between a Ray and a triangle.
public static bool RayIntersectsTriangle(ref Ray ray, ref Vector3 vertex1, ref Vector3 vertex2, ref Vector3 vertex3, out Vector3 point)
Parameters
rayRayThe ray to test.
vertex1Vector3The first vertex of the triangle to test.
vertex2Vector3The second vertex of the triangle to test.
vertex3Vector3The third vertex of the triangle to test.
pointVector3When the method completes, contains the point of intersection, or Zero if there was no intersection.
Returns
- bool
Whether the two objects intersected.
RayIntersectsTriangle(ref Ray, ref Vector3, ref Vector3, ref Vector3, out float)
Determines whether there is an intersection between a Ray and a triangle.
public static bool RayIntersectsTriangle(ref Ray ray, ref Vector3 vertex1, ref Vector3 vertex2, ref Vector3 vertex3, out float distance)
Parameters
rayRayThe ray to test.
vertex1Vector3The first vertex of the triangle to test.
vertex2Vector3The second vertex of the triangle to test.
vertex3Vector3The third vertex of the triangle to test.
distancefloatWhen the method completes, contains the distance of the intersection, or 0 if there was no intersection.
Returns
- bool
Whether the two objects intersected.
Remarks
This method tests if the ray intersects either the front or back of the triangle. If the ray is parallel to the triangle's plane, no intersection is assumed to have happened. If the intersection of the ray and the triangle is behind the origin of the ray, no intersection is assumed to have happened. In both cases of assumptions, this method returns false.
SphereContainsBox(ref BoundingSphere, ref BoundingBox)
Determines whether a BoundingSphere contains a BoundingBox.
public static ContainmentType SphereContainsBox(ref BoundingSphere sphere, ref BoundingBox box)
Parameters
sphereBoundingSphereThe sphere to test.
boxBoundingBoxThe box to test.
Returns
- ContainmentType
The type of containment the two objects have.
SphereContainsPoint(ref BoundingSphere, ref Vector3)
Determines whether a BoundingSphere contains a point.
public static ContainmentType SphereContainsPoint(ref BoundingSphere sphere, ref Vector3 point)
Parameters
sphereBoundingSphereThe sphere to test.
pointVector3The point to test.
Returns
- ContainmentType
The type of containment the two objects have.
SphereContainsSphere(ref BoundingSphere, ref BoundingSphere)
Determines whether a BoundingSphere contains a BoundingSphere.
public static ContainmentType SphereContainsSphere(ref BoundingSphere sphere1, ref BoundingSphere sphere2)
Parameters
sphere1BoundingSphereThe first sphere to test.
sphere2BoundingSphereThe second sphere to test.
Returns
- ContainmentType
The type of containment the two objects have.
SphereContainsTriangle(ref BoundingSphere, ref Vector3, ref Vector3, ref Vector3)
Determines whether a BoundingSphere contains a triangle.
public static ContainmentType SphereContainsTriangle(ref BoundingSphere sphere, ref Vector3 vertex1, ref Vector3 vertex2, ref Vector3 vertex3)
Parameters
sphereBoundingSphereThe sphere to test.
vertex1Vector3The first vertex of the triangle to test.
vertex2Vector3The second vertex of the triangle to test.
vertex3Vector3The third vertex of the triangle to test.
Returns
- ContainmentType
The type of containment the two objects have.
SphereIntersectsSphere(ref BoundingSphere, ref BoundingSphere)
Determines whether there is an intersection between a BoundingSphere and a BoundingSphere.
public static bool SphereIntersectsSphere(ref BoundingSphere sphere1, ref BoundingSphere sphere2)
Parameters
sphere1BoundingSphereFirst sphere to test.
sphere2BoundingSphereSecond sphere to test.
Returns
- bool
Whether the two objects intersected.
SphereIntersectsTriangle(ref BoundingSphere, ref Vector3, ref Vector3, ref Vector3)
Determines whether there is an intersection between a BoundingSphere and a triangle.
public static bool SphereIntersectsTriangle(ref BoundingSphere sphere, ref Vector3 vertex1, ref Vector3 vertex2, ref Vector3 vertex3)
Parameters
sphereBoundingSphereThe sphere to test.
vertex1Vector3The first vertex of the triangle to test.
vertex2Vector3The second vertex of the triangle to test.
vertex3Vector3The third vertex of the triangle to test.
Returns
- bool
Whether the two objects intersected.