Intersection Helper
1.0
Library of helper functions to test intersections between 3D shapes
|
Class of static functions to help with intersection calculations More...
Static Public Member Functions | |
static float | DistanceLineLine (Vector3 lineAPoint, Vector3 lineADirection, Vector3 lineBPoint, Vector3 lineBDirection) |
Gets the shortest distance between two infinite lines. More... | |
static float | SqrDistanceSegmentToSegment (Vector3 segment0Point0, Vector3 segment0Point1, Vector3 segment1Point0, Vector3 segment1Point1, out float closestPoint0, out float closestPoint1) |
Gets the square of shortest distance between two finite line segments. More... | |
static float | SqrDistancePointTriangle (Vector3 point, Vector3 triangle0, Vector3 triangle1, Vector3 triangle2, out Vector3 closestPoint) |
Gets the square of shortest distance between a point and a triangle in 3D space. More... | |
static bool | IsPointInTriangle (Vector3 p0, Vector3 p1, Vector3 p2, Vector3 point) |
Checks if a point lies inside a triangle More... | |
static bool | GetPlaneFromTriangle (Vector3 t0, Vector3 t1, Vector3 t2, out Vector3 outPlanePoint, out Vector3 outPlaneNormal) |
Gets a point and normal direction representing the plane containing a given triangle. More... | |
static Vector3 | PointSegmentProjection (Vector3 point, Vector3 segPoint0, Vector3 segPoint1) |
Gets the projection of a point on a finite line segment. More... | |
static bool | ClosestPointsLineToLine (Vector3 p1, Vector3 p2, Vector3 p3, Vector3 p4, out Vector3 pa, out Vector3 pb) |
Gets the closest point between two infinite lines. More... | |
static bool | IntersectAABBoxWithOOBBox (Vector3 minA, Vector3 maxA, Matrix4x4 matrixB, Vector3 minB, Vector3 maxB) |
Determines if an AABB box intersects with an OOBB box. More... | |
static bool | IntersectCapsuleWithCapsule (Vector3 capsule0Point0, Vector3 capsule0Point1, float capsule0Radius, Vector3 capsule1Point0, Vector3 capsule1Point1, float capsule1Radius) |
Determines if a capsule intersects with another capsule More... | |
static bool | IntersectCapsuleWithCapsule (Vector3 capsule0Point0, Vector3 capsule0Point1, float capsule0Radius, Vector3 capsule1Point0, Vector3 capsule1Point1, float capsule1Radius, out Vector3 collisionPointOnCapsule1, out Vector3 pushBackVector) |
Determines if a capsule intersects with another capsule, returning the intersection point on the outer surface of capsule1 and the pushback vector to separate capsule1 away from capsule0 More... | |
static bool | IntersectInfinitePlaneWithInfinitePlane (Vector3 planeNormal0, Vector3 planePoint0, Vector3 planeNormal1, Vector3 planePoint1, out Vector3 linePoint, out Vector3 lineDirection) |
Determines if two planes intersect. If yes, it also returns the line that intersects the two planes. More... | |
static bool | IntersectLineWithInfinitePlane (Vector3 linePoint, Vector3 lineDir, Vector3 planePoint, Vector3 planeDir, out Vector3 intersectionPoint) |
Determines if a line intersects with a plane, and if yes, also returns the intersection point. More... | |
static bool | IntersectLineWithTriangle (Vector3 linePoint, Vector3 lineDir, Vector3 t0, Vector3 t1, Vector3 t2, out Vector3 outContact) |
Determines if a infinite line intersects with a triangle, and if yes, also returns the intersection point. More... | |
static bool | IntersectLineWithLine (Vector3 line0Point, Vector3 line0Vec, Vector3 line1Point, Vector3 line1Vec, out Vector3 intersectionPoint) |
Determines if two infinite lines intersect each other More... | |
static int | IntersectLineWithCapsule (Vector3 pointOnLine, Vector3 lineDirection, Vector3 capsuleOrigin, Vector3 capsuleDirection, float capsuleRadius, out float[] afT) |
Determines if an infinite line intersects a capsule More... | |
static bool | IntersectOOBBoxWithOOBBox (Matrix4x4 matrixA, Vector3 minA, Vector3 maxA, Matrix4x4 matrixB, Vector3 minB, Vector3 maxB) |
Determines if an OOBB box intersects another OOBB box More... | |
static bool | IntersectPointWithAABBox (Vector3 point, Vector3 minA, Vector3 maxA) |
Determines if a point lies inside an AABB box More... | |
static bool | IntersectPointWithOOBBox (Vector3 point, Matrix4x4 matrix, Vector3 min, Vector3 max) |
Determines if a point lies inside an OOBB box More... | |
static bool | IntersectPointWithSphere (Vector3 point, Vector3 center, float radius) |
Determines if a point lies inside a sphere More... | |
static bool | IntersectPointWithCapsule (Vector3 point, Vector3 capsulePoint0, Vector3 capsulePoint1, float capsuleRadius) |
Determines if a point lies inside a capsule More... | |
static bool | IntersectPointWithTube (Vector3 point, Vector3 tubeStart, Vector3 tubeEnd, float radiusStart, float radiusEnd) |
Determines if a point lies inside a tube More... | |
static bool | IntersectRayAABBox (Vector3 originRay, Vector3 dirRay, Vector3 minBox, Vector3 maxBox, out Vector3 coord) |
Determines if a ray starting from a given point intersects with an AABB box More... | |
static bool | IntersectRayOOBBox (Vector3 originRay, Vector3 dirRay, Matrix4x4 matrixBox, Vector3 minBox, Vector3 maxBox, out Vector3 coord) |
Determines if a ray starting from a given point intersects with an OOBB box More... | |
static bool | IntersectRayWithCylinder (Vector3 rayOrigin, Vector3 ray, Vector3 cylinderBasis, Vector3 cylinderAxis, float radius, float height, out float dist, out Vector3 hitPoint, out float distOnCylinder) |
Determines if a ray starting from a given point intersects with a cylinder More... | |
static int | IntersectSegmentWithCapsule (Vector3 segmentPoint, Vector3 segmentDirection, Vector3 capsuleOrigin, Vector3 capsuleDirection, float capsuleRadius, out Vector3[] intersectionPoints) |
Determines if a finite segment intersects with a capsule More... | |
static bool | IntersectSegmentWithCapsule (Vector3 segmentPoint0, Vector3 segmentPoint1, Vector3 capsulePoint0, Vector3 capsulePoint1, float capsuleRadius) |
Determines if a finite segment intersects with a capsule More... | |
static bool | IntersectSegmentWithInfinitePlane (Vector3 p0, Vector3 p1, Vector3 planeOrigin, Vector3 planeNormal, out Vector3 outContact) |
Determines if a finite segment intersects with a plane More... | |
static bool | IntersectSegmentWithSegment (Vector3 segAPoint0, Vector3 segAPoint1, Vector3 segBPoint0, Vector3 segBPoint1, out Vector3 intersectionPoint, out float sFactor, out float tFactor) |
Determines if two finite segments intersect More... | |
static bool | IntersectSegmentWithTriangle (Vector3 p0, Vector3 p1, Vector3 t0, Vector3 t1, Vector3 t2, out Vector3 outContact) |
Determines if a finite segment intersects with a triangle More... | |
static bool | IntersectSegmentAABBox (Vector3 point0Seg, Vector3 point1Seg, Vector3 minBox, Vector3 maxBox, out Vector3 coord0, out Vector3 coord1) |
Determines if a finite segment intersects an AABB box More... | |
static bool | IntersectSegmentWithOOBBox (Vector3 segPoint0, Vector3 segPoint1, Matrix4x4 boxMatrix, Vector3 boxMin, Vector3 boxMax) |
Determines if a finite segment intersects with an OOBB box More... | |
static bool | IntersectSegmentWithOOBBox (Vector3 point0Seg, Vector3 point1Seg, Matrix4x4 matrixBox, Vector3 minBox, Vector3 maxBox, out Vector3 coord0, out Vector3 coord1) |
Determines if a finite segment intersects with an OOBB box, returning the intersection points More... | |
static bool | IntersectSegmentWithSphere (Vector3 segPoint0, Vector3 segPoint1, Vector3 sphereCenter, float sphereRadius) |
Determines if a finite segment intersects a sphere More... | |
static bool | IntersectSphereWithAABBox (Vector3 center, float radius, Vector3 min, Vector3 max) |
Determines if a sphere intersects with an AABB box More... | |
static bool | IntersectSphereWithOOBBox (Vector3 center, float radius, Matrix4x4 matrix, Vector3 min, Vector3 max) |
Determines if a sphere intersects with an OOBB box More... | |
static bool | IntersectSphereWithCapsule (Vector3 sphereCenter, float sphereRadius, Vector3 capsulePoint0, Vector3 capsulePoint1, float capsuleRadius, out Vector3 pushBackVector) |
Determines if a sphere intersects with a capsule More... | |
static bool | IntersectTriangleOOBBox (Vector3 point0Seg, Vector3 point1Seg, Vector3 point2Seg, Matrix4x4 matrixBox, Vector3 minBox, Vector3 maxBox) |
Determines if a triangle intersects with an OOBB box More... | |
Class of static functions to help with intersection calculations
|
static |
Gets the closest point between two infinite lines.
p1 | A point on the first line |
p2 | Another point on the first line |
p3 | A point on the second line |
p4 | Another point on the second line |
pa | The closest point (on the first line) between the two lines |
pb | The closest point (on the second line) between the two lines |
|
static |
Gets the shortest distance between two infinite lines.
lineAPoint | A point that the first line passes through |
lineADirection | The normalized direction vector of the first line |
lineBPoint | A point that the second line passes through |
lineBDirection | The normalized direction vector of the second line. |
|
static |
Gets a point and normal direction representing the plane containing a given triangle.
t0 | The first point of the triangle |
t1 | The second point of the triangle |
t2 | The third point of the triangle |
outPlanePoint | [output] A point on the plane |
outPlaneNormal | [output] The direction of the normal of the plane |
|
static |
Determines if an AABB box intersects with an OOBB box.
minA | The minimum extents of the AABB box |
maxA | The maximum extents of the AABB box |
matrixB | The matrix representing the position, rotation and scale of the OOBB box. This matrix would be equivalent to Matrix4x4.TRS(positionVector, rotationQuat, scaleVector) |
minB | The minimum extents (in local space) of the OOBB box |
maxB | The maximum extents (in local space) of the OOBB box |
|
static |
Determines if a capsule intersects with another capsule
capsule0Point0 | The base point of the first capsule |
capsule0Point1 | The end point of the first capsule |
capsule0Radius | The radius of the first capsule |
capsule1Point0 | The base point of the second capsule |
capsule1Point1 | The end point of the second capsule |
capsule1Radius | The radius of the second capsule |
|
static |
Determines if a capsule intersects with another capsule, returning the intersection point on the outer surface of capsule1 and the pushback vector to separate capsule1 away from capsule0
capsule0Point0 | The base point of the first capsule |
capsule0Point1 | The end point of the first capsule |
capsule0Radius | The radius of the first capsule |
capsule1Point0 | The base point of the second capsule |
capsule1Point1 | The end point of the second capsule |
capsule1Radius | The radius of the second capsule |
collisionPointOnCapsule1 | [output] The collision point on the outer surface of the second capsule, if the two capsules intersect |
pushBackVector | [output] The pushback vector that needs to be applied on the second capsule to separate the capsules. |
|
static |
Determines if two planes intersect. If yes, it also returns the line that intersects the two planes.
planeNormal0 | The normal direction of the first plane |
planePoint0 | A point on the first plane |
planeNormal1 | The normal direction of the second plane |
planePoint1 | A point on the second plane |
linePoint | [output] A point on the line that intersects the two planes |
lineDirection | [output] The direction vector of the line that intersects the two planes |
|
static |
Determines if an infinite line intersects a capsule
pointOnLine | A point on the line |
lineDirection | The normalised direction vector of the line |
capsuleOrigin | The origin of the capsule |
capsuleDirection | The direction vector of the capsule, multiplied by the length of the capsule |
capsuleRadius | The radius of the capsule |
afT | [output] Array (size 2) of t-values of the line that represent the intersection points |
|
static |
Determines if a line intersects with a plane, and if yes, also returns the intersection point.
linePoint | A point on the line |
lineDir | The normalised direction vector of the line |
planePoint | A point on the plane |
planeDir | The normal of the plane |
intersectionPoint | [output] The intersection point between the line and the plane |
|
static |
Determines if two infinite lines intersect each other
line0Point | A point on the first line |
line0Vec | The normalised direction vector of the first line |
line1Point | A point on the second line |
line1Vec | The normalised direction vector of the second line |
intersectionPoint | [output] The intersection point of the two lines |
|
static |
Determines if a infinite line intersects with a triangle, and if yes, also returns the intersection point.
linePoint | A point on the line |
lineDir | The normalised direction vector of the line |
t0 | The first point of the triangle |
t1 | The second point of the triangle |
t2 | The third point of the triangle |
outContact | [output] The intersection point of the line and the triangle |
|
static |
Determines if an OOBB box intersects another OOBB box
matrixA | The matrix representing the position, rotation and scale of the first OOBB box. This matrix would be equivalent to Matrix4x4.TRS(positionVector, rotationQuat, scaleVector) |
minA | The minimum extents (in local space) of the first OOBB box |
maxA | The maximum extents (in local space) of the first OOBB box |
matrixB | The matrix representing the position, rotation and scale of the second OOBB box. This matrix would be equivalent to Matrix4x4.TRS(positionVector, rotationQuat, scaleVector) |
minB | The minimum extents (in local space) of the second OOBB box |
maxB | The maximum extents (in local space) of the second OOBB box |
|
static |
Determines if a point lies inside an AABB box
point | The coordinates of the point |
minA | The minimum extents of the AABB box |
maxA | The maximum extents of the AABB box |
|
static |
Determines if a point lies inside a capsule
point | The coordinates of the point |
capsulePoint0 | The coordinates of the base of the capsule |
capsulePoint1 | The coordinates of the end of the capsule |
capsuleRadius | The radius of the capsule |
|
static |
Determines if a point lies inside an OOBB box
point | The coordinates of the point |
matrix | The matrix representing the position, rotation and scale of the OOBB box. This matrix would be equivalent to Matrix4x4.TRS(positionVector, rotationQuat, scaleVector) |
min | The minimum extents (in local space) of the OOBB box |
max | The maximum extents (in local space) of the OOBB box |
|
static |
Determines if a point lies inside a sphere
point | The coordinates of the point |
center | The coordinates of the center of the sphere |
radius | The radius of the sphere |
|
static |
Determines if a point lies inside a tube
point | The coordinates of the point |
tubeStart | The first end of the tube |
tubeEnd | The other end of the tube |
radiusStart | The radius of the tube at the first end |
radiusEnd | The radius of the tube at the other end |
|
static |
Determines if a ray starting from a given point intersects with an AABB box
originRay | The origin of the ray |
dirRay | The normalised direction vector of the ray |
minBox | The minimum extents of the AABB box |
maxBox | The maximum extents of the AABB box |
coord | [output] The coordinates of the intersection point |
|
static |
Determines if a ray starting from a given point intersects with an OOBB box
originRay | The origin of the ray |
dirRay | The normalised direction vector of the ray |
matrixBox | The matrix representing the position, rotation and scale of the OOBB box. This matrix would be equivalent to Matrix4x4.TRS(positionVector, rotationQuat, scaleVector) |
minBox | The minimum extents (in local space) of the OOBB box |
maxBox | The maximum extents (in local space) of the OOBB box |
coord | [output] The coordinates of the intersection point |
|
static |
Determines if a ray starting from a given point intersects with a cylinder
rayOrigin | The origin of the ray |
ray | The normalised direction vector of the ray |
cylinderBasis | The coordinates of the base of the cylinder |
cylinderAxis | The direction vector of the axis of the cylinder |
radius | The radius of the cylinder |
height | The height of the cylinder |
dist | [output] The distance of the intersection point from the start of the ray |
hitPoint | [output] The coordinates of the intersection point |
distOnCylinder | [output] The distance of the intersection point along the cylinder |
|
static |
Determines if a finite segment intersects an AABB box
point0Seg | The start of the segment |
point1Seg | The end of the segment |
minBox | The minimum extents of the AABB box |
maxBox | The maximum extents of the AABB box |
coord0 | [output] The first intersection point |
coord1 | [output] The second intersection point |
|
static |
Determines if a finite segment intersects with a capsule
segmentPoint | The start of the segment |
segmentDirection | The direction vector of the segment, multiplied by it's length |
capsuleOrigin | The coordinates of the origin of the capsule |
capsuleDirection | The direction vector of the axis of the capsule |
capsuleRadius | The radius of the capsule |
intersectionPoints | [output] The intersection points between the segment and the capsule |
|
static |
Determines if a finite segment intersects with a capsule
segmentPoint0 | The start of the segment |
segmentPoint1 | The end of the segment |
capsulePoint0 | The coordinates of the base of the capsule |
capsulePoint1 | The coordinates of the end of the capsule |
capsuleRadius | The radius of the capsule |
|
static |
Determines if a finite segment intersects with a plane
p0 | The start of the segment |
p1 | The end of the segment |
planeOrigin | A point on the plane |
planeNormal | The normal direction vector of the plane |
outContact | [output] the intersection point of the segment with the plane |
|
static |
Determines if a finite segment intersects with an OOBB box
segPoint0 | The start of the segment |
segPoint1 | The end of the segment |
boxMatrix | The matrix representing the position, rotation and scale of the OOBB box. This matrix would be equivalent to Matrix4x4.TRS(positionVector, rotationQuat, scaleVector) |
boxMin | The minimum extents (in local space) of the OOBB box |
boxMax | The maximum extents (in local space) of the OOBB box |
|
static |
Determines if a finite segment intersects with an OOBB box, returning the intersection points
point0Seg | The start of the segment |
point1Seg | The end of the segment |
matrixBox | The matrix representing the position, rotation and scale of the OOBB box. This matrix would be equivalent to Matrix4x4.TRS(positionVector, rotationQuat, scaleVector) |
minBox | The minimum extents (in local space) of the OOBB box |
maxBox | The maximum extents (in local space) of the OOBB box |
coord0 | [output] The first intersection point |
coord1 | [output] The second intersection point |
|
static |
Determines if two finite segments intersect
segAPoint0 | The start of the first segment |
segAPoint1 | The end of the first segment |
segBPoint0 | The start of the second segment |
segBPoint1 | A end on the second plane |
sFactor | [output] The ratio of the intersection point along the first segment |
tFactor | [output] The ratio of the intersection point along the second segment |
intersectionPoint | [output] The intersection point of the two segments |
|
static |
Determines if a finite segment intersects a sphere
segPoint0 | The start of the segment |
segPoint1 | The end of the segment |
sphereCenter | The point at the center of the sphere |
sphereRadius | The radius of the sphere |
|
static |
Determines if a finite segment intersects with a triangle
p0 | The start of the segment |
p1 | The end of the segment |
t0 | The first point of the triangle |
t1 | The second point of the triangle |
t2 | The third point of the triangle |
outContact | [output] the intersection point of the segment with the triangle |
|
static |
Determines if a sphere intersects with an AABB box
center | The point at the center of the sphere |
radius | The radius of the sphere |
min | The minimum extents of the AABB box |
max | The maximum extents of the AABB box |
|
static |
Determines if a sphere intersects with a capsule
sphereCenter | The point at the center of the sphere |
sphereRadius | The radius of the sphere |
capsulePoint0 | The base of the capsule |
capsulePoint1 | The end of the capsule |
capsuleRadius | The radius of the capsule |
pushBackVector | [output] The pushback vector to separate the sphere from the capsule |
|
static |
Determines if a sphere intersects with an OOBB box
center | The point at the center of the sphere |
radius | The radius of the sphere |
matrix | The matrix representing the position, rotation and scale of the OOBB box. This matrix would be equivalent to Matrix4x4.TRS(positionVector, rotationQuat, scaleVector) |
min | The minimum extents (in local space) of the OOBB box |
max | The maximum extents (in local space) of the OOBB box |
|
static |
Determines if a triangle intersects with an OOBB box
point0Seg | The first point of the triangle |
point1Seg | The second point of the triangle |
point2Seg | The third point of the triangle |
matrixBox | The matrix representing the position, rotation and scale of the OOBB box. This matrix would be equivalent to Matrix4x4.TRS(positionVector, rotationQuat, scaleVector) |
minBox | The minimum extents (in local space) of the OOBB box |
maxBox | The maximum extents (in local space) of the OOBB box |
|
static |
Checks if a point lies inside a triangle
p0 | The first point of the triangle |
p1 | The second point of the triangle |
p2 | The third point of the triangle |
point | The position of the desired point. |
|
static |
Gets the projection of a point on a finite line segment.
point | The input point |
segPoint0 | The start of the line segment |
segPoint1 | The end of the line segment |
|
static |
Gets the square of shortest distance between a point and a triangle in 3D space.
point | The position of the desired point. |
triangle0 | The first point of the triangle |
triangle1 | The second point of the triangle |
triangle2 | The third point of the triangle |
closestPoint | [output] The closest point (on the plane) to the input point. |
|
static |
Gets the square of shortest distance between two finite line segments.
segment0Point0 | The start position of the first segment |
segment0Point1 | The end position of the first segment |
segment1Point0 | The start position of the second segment |
segment1Point1 | The end position of the second segment |
closestPoint0 | [output] The ratio (along the first segment) of the closest point. |
closestPoint1 | The ratio (along the second segment) of the closest point. |