A collection of collision helper functions. More...
Static Public Member Functions | |
static Boolean | BoxIntersectsBox (FPVector2 aCenter, FPVector2 aExtents, FP aRotation, FPVector2 bCenter, FPVector2 bExtents, FP bRotation) |
Box-Box (2D) intersection test. More... | |
static Boolean | CircleContainsPoint (FPVector2 center, FP radius, FPVector2 point) |
Checks if point is inside a circle, including its circumference. Works for CW and CWW. More... | |
static Boolean | CircleIntersectsAABB (FPVector2 center, FP radius, FPVector2 min, FPVector2 max) |
Circle-AABB intersection test. More... | |
static Boolean | CircleIntersectsCircle (FPVector2 a_origin, FP a_radius, FPVector2 b_origin, FP b_radius) |
Circle-circle intersection test. More... | |
static Boolean | CircleIntersectsPolygon (FPVector2 circleCenter, FP circleRadius, FPVector2 polygonPosition, FP polygonRotation, FPVector2[] polygonVertices, FPVector2[] polygonNormals) |
Circle-polygon intersection test. More... | |
static Boolean | CircleIntersectsPolygon (FPVector2 circleCenter, FP circleRadius, FPVector2 polygonPosition, FP polygonRotationSinInverse, FP polygonRotationCosInverse, FPVector2[] polygonVertices, FPVector2[] polygonNormals) |
Circle-polygon intersection test. More... | |
static Boolean | CircleIntersectsTriangle (FPVector2 center, FP radius, FPVector2 v1, FPVector2 v2, FPVector2 v3) |
Circle-triangle intersection test. More... | |
static bool | ClampPointToAABB (FPVector2 point, FPVector2 boxExtents, out FPVector2 clampedPoint) |
Clamps a 2D point to an axis-aligned bounding box (AABB). More... | |
static bool | ClampPointToLocalAABB (FPVector3 point, FPVector3 aabbExtents, out FPVector3 clampedPoint) |
Checks if a point is inside the extents of an AABB centered at the origin (local space) and clamp it otherwise. More... | |
static FP | ClosestDistanceToTriangle (FPVector3 p, FPVector3 a, FPVector3 b, FPVector3 c, out FPVector3 closestPoint, out FPVector3 barycentricCoordinates) |
Uses barycentric coordinates to calculate the closest point on a triangle. In conjunction with Fixed Point math this can get quite inaccurate when the triangle become large (more than 100 units) or tiny (less then 0.01 units). More... | |
static FPVector2 | ClosestPointBetweenSegments (FPVector2 segment1Start, FPVector2 segment1End, FPVector2 segment2Start, FPVector2 segment2End) |
Computes the closes point in segment A to a segment B. More... | |
static FPVector3 | ClosestPointBetweenSegments (FPVector3 segmentStartA, FPVector3 segmentEndA, FPVector3 segmentStartB, FPVector3 segmentEndB) |
Computes the closes point in segment A to a segment B. More... | |
static FPVector3 | ClosestPointInSegment (FPVector3 point, FPVector3 a, FPVector3 b) |
Calculates the closest point on the line segment defined by two given points to a given point. More... | |
static FPVector2 | ClosestPointOnCicle (FPVector2 center, FP radius, FPVector2 pt) |
Casts a point pt on a circle. More... | |
static FPVector2 | ClosestPointOnSegment (FPVector2 point, FPVector2 p1, FPVector2 p2) |
Cast point point on a line crossing p1 and p2 . The result is clamped to lie on a segment defined by p1 and p2 . More... | |
static FPVector3 | ClosestPointOnSegment (FPVector3 point, FPVector3 p1, FPVector3 p2) |
Returns the closest point on a segment to a given point. More... | |
static FPVector2 | ClosestPointOnTriangle (FPVector2 pt, FPVector2 t0, FPVector2 t1, FPVector2 t2) |
Casts a point pt on a triangle defined by three vertices. More... | |
static Boolean | InsideAABB (FPVector2 point, FPVector2 extents, out FP penetration) |
Returns true if point is inside centered AABB. More... | |
static bool | IsPointOnLine (FPVector2 p1, FPVector2 p2, FPVector2 point) |
Returns true if a point point lies on a line crossing p1 and p2 . More... | |
static Int32 | LineIntersectsAABB (FPVector2 p1, FPVector2 p2, FPVector2 aabbCenter, FPVector2 aabbExtents, out FPVector2 i1, out FPVector2 i2, out FP penetration) |
Line segment-AABB intersection test in world space with computation of intersection points and penetration. More... | |
static Int32 | LineIntersectsAABB (FPVector2 p1, FPVector2 p2, FPVector2 aabbExtents, out FPVector2 i1, out FPVector2 i2, out FP penetration) |
Line segment-AABB intersection test in the LOCAL space of the AABB with computation of intersection points and penetration. More... | |
static Boolean | LineIntersectsAABB2 (FPVector2 p1, FPVector2 p2, FPVector2 normal, FPVector2 aabbCenter, FPVector2 aabbExtents, out FPVector2 i1, out FPVector2 i2, out FP penetration) |
Line segment-AABB intersection test in world space with computation of intersection points, normal and penetration. If an intersection is detected, the test always returns two intersection points, which can be either intersections between the line segment and an edge of the AABB or a segment point itself, if inside the AABB. More... | |
static Boolean | LineIntersectsAABB2 (FPVector2 p1, FPVector2 p2, FPVector2 normal, FPVector2 aabbExtents, out FPVector2 i1, out FPVector2 i2, out FP penetration) |
Line segment-AABB intersection test in the LOCAL space of the AABB with computation of intersection points, normal and penetration. If an intersection is detected, the test always returns two intersection points, which can be either intersections between the line segment and an edge of the AABB or a segment point itself, if inside the AABB. More... | |
static Boolean | LineIntersectsAABB_SAT (FPVector2 p1, FPVector2 p2, FPVector2 aabbCenter, FPVector2 aabbExtents) |
Line segment-AABB intersection test. More... | |
static Boolean | LineIntersectsAABB_SAT (FPVector2 p1, FPVector2 p2, FPVector2 aabbExtents) |
Line segment-AABB intersection test in the LOCAL space of the AABB. More... | |
static Boolean | LineIntersectsCircle (FPVector2 p1, FPVector2 p2, FPVector2 position, FP radius, bool ignoreIfStartPointInside=false) |
Line segment-circle intersection test. More... | |
static Boolean | LineIntersectsCircle (FPVector2 p1, FPVector2 p2, FPVector2 position, FP radius, out FPVector2 point, bool ignoreIfStartPointInside=false) |
Line segment-circle intersection test. More... | |
static Boolean | LineIntersectsCircle (FPVector2 p1, FPVector2 p2, FPVector2 position, FP radius, out FPVector2 point, out FP normalizedDist, bool ignoreIfStartPointInside=false) |
Line segment-circle intersection test. More... | |
static Boolean | LineIntersectsCircleManifold (FPVector2 p1, FPVector2 p2, FPVector2 position, FP radius, out FPVector2 point) |
Line segment-circle intersection test. More... | |
static bool | LineIntersectsLine (FPVector2 p1, FPVector2 p2, FPVector2 q1, FPVector2 q2) |
Line segment-line segment intersection test. More... | |
static bool | LineIntersectsLine (FPVector2 p1, FPVector2 p2, FPVector2 q1, FPVector2 q2, out FPVector2 point) |
Line segment-line segment intersection test. More... | |
static bool | LineIntersectsLine (FPVector2 p1, FPVector2 p2, FPVector2 q1, FPVector2 q2, out FPVector2 point, out FP distance) |
Line segment-line segment intersection test. More... | |
static bool | LineIntersectsLine (FPVector2 p1, FPVector2 p2, FPVector2 q1, FPVector2 q2, out FPVector2 point, out FP distance, out FP normalizedDist) |
Determines if two lines intersect. More... | |
static void | LineIntersectsLineAlwaysHit (FPVector2 p1, FPVector2 p2, FPVector2 q1, FPVector2 q2, out FPVector2 point) |
Line segment-line segment intersection test. Assumes lines are not colinear nor parallel. More... | |
static FPVector2 | TriangleCenter (FPVector2 v0, FPVector2 v1, FPVector2 v2) |
Returns the center of a triangle defined by three vertices. More... | |
static Boolean | TriangleContainsPointExclusive (FPVector2 pt, FPVector2 v0, FPVector2 v1, FPVector2 v2) |
Checks if pt is inside a triangle, excluding vertices and edges. Works for CW and CWW. More... | |
static Boolean | TriangleContainsPointExclusive (FPVector3 pt, FPVector3 v0, FPVector3 v1, FPVector3 v2) |
Checks if pt is inside a triangle, excluding vertices and edges. This only checks the XZ component like the triangle is in 2D! Works for CW and CWW. More... | |
static Boolean | TriangleContainsPointInclusive (FPVector2 pt, FPVector2 v0, FPVector2 v1, FPVector2 v2) |
Checks if pt is inside a triangle, including edges and vertices. Works for CW and CWW. More... | |
static Boolean | TriangleContainsPointInclusive (FPVector3 pt, FPVector3 v0, FPVector3 v1, FPVector3 v2) |
Checks if pt is inside a triangle, including edges and vertices. This only checks the XZ component like the triangle is in 2D! Works for CW and CWW. More... | |
A collection of collision helper functions.
|
inlinestatic |
Returns the center of a triangle defined by three vertices.
v0 | |
v1 | |
v2 |
|
inlinestatic |
Returns true
if a point point lies on a line crossing p1 and p2 .
p1 | |
p2 | |
point |
|
inlinestatic |
Returns the closest point on a segment to a given point.
point | The point to find the closest point on the segment to. |
p1 | The start point of the segment. |
p2 | The end point of the segment. |
|
inlinestatic |
Cast point point on a line crossing p1 and p2 . The result is clamped to lie on a segment defined by p1 and p2 .
point | |
p1 | |
p2 |
|
inlinestatic |
Clamps a 2D point to an axis-aligned bounding box (AABB).
point | The point to clamp. |
boxExtents | The half extents of the AABB. The AABB is centered at the origin. |
clampedPoint | The clamped point will be stored in this output parameter. |
true
if the original point is inside the AABB, or false
if it is outside. The clamped point will always be inside the AABB.
|
inlinestatic |
Computes the closes point in segment A to a segment B.
segment1Start | Start point of segment A. |
segment1End | End point of segment A. |
segment2Start | Start point of segment A. |
segment2End | End point of segment B. |
|
inlinestatic |
Casts a point pt on a triangle defined by three vertices.
pt | |
t0 | |
t1 | |
t2 |
|
inlinestatic |
Casts a point pt on a circle.
center | |
radius | |
pt |
|
inlinestatic |
Checks if pt is inside a triangle, excluding vertices and edges. Works for CW and CWW.
pt | Point to check |
v0 | vertex position 0 |
v1 | vertex position 1 |
v2 | vertex position 2 |
true
if pt is inside the triangle. false
if point is outside or if the point is located on an edge or vertex.
|
inlinestatic |
Checks if pt is inside a triangle, excluding vertices and edges. This only checks the XZ component like the triangle is in 2D! Works for CW and CWW.
pt | Point to check |
v0 | vertex position 0 |
v1 | vertex position 1 |
v2 | vertex position 2 |
true
if pt is inside the triangle. false
if point is outside or if the point is located on an edge or vertex.
|
inlinestatic |
Checks if pt is inside a triangle, including edges and vertices. Works for CW and CWW.
pt | Point to check |
v0 | vertex position 0 |
v1 | vertex position 1 |
v2 | vertex position 2 |
true
if pt is inside the triangle or is located on an edge or vertex.
|
inlinestatic |
Checks if pt is inside a triangle, including edges and vertices. This only checks the XZ component like the triangle is in 2D! Works for CW and CWW.
pt | Point to check |
v0 | vertex position 0 |
v1 | vertex position 1 |
v2 | vertex position 2 |
true
if pt is inside the triangle or is located on an edge or vertex.
|
inlinestatic |
Checks if point is inside a circle, including its circumference. Works for CW and CWW.
center | |
radius | |
point |
true
in point point is inside the circle.
|
inlinestatic |
Circle-circle intersection test.
a_origin | |
a_radius | |
b_origin | |
b_radius |
|
inlinestatic |
Circle-AABB intersection test.
center | |
radius | |
min | |
max |
|
inlinestatic |
Circle-triangle intersection test.
center | |
radius | |
v1 | |
v2 | |
v3 |
|
inlinestatic |
Line segment-AABB intersection test.
p1 | First point that defines the line segment in world space. |
p2 | Second point that defines the line segment in world space. |
aabbCenter | The center of the AABB in world space. |
aabbExtents | The distance between the AABB center and the max X and Y values in world space. |
true
if the line segment intersects the AABB and false
otherwise.
|
inlinestatic |
Line segment-AABB intersection test in the LOCAL space of the AABB.
p1 | First point that defines the line segment, relative to the AABB center. |
p2 | Second point that defines the line segment, relative to the AABB center. |
aabbExtents | The distance between the AABB center and the max X and Y values. |
true
if the line segment intersects the AABB and false
otherwise.
|
inlinestatic |
Line segment-AABB intersection test in world space with computation of intersection points, normal and penetration. If an intersection is detected, the test always returns two intersection points, which can be either intersections between the line segment and an edge of the AABB or a segment point itself, if inside the AABB.
p1 | First point that defines the line segment in world space. |
p2 | Second point that defines the line segment in world space. |
normal | Normal along which the line segment penetration will be computed. |
aabbCenter | The center of the AABB in world space. |
aabbExtents | The distance between the AABB center and the max X and Y values in world space. |
i1 | First intersection point. |
i2 | Second intersection point. |
penetration | The penetration of the line segment along the normal . |
true
if the line segment intersects the AABB and false
otherwise.
|
inlinestatic |
Line segment-AABB intersection test in the LOCAL space of the AABB with computation of intersection points, normal and penetration. If an intersection is detected, the test always returns two intersection points, which can be either intersections between the line segment and an edge of the AABB or a segment point itself, if inside the AABB.
p1 | First point that defines the line segment, relative to the AABB center. |
p2 | Second point that defines the line segment, relative to the AABB center. |
normal | Normal along which the line segment penetration will be computed. |
aabbExtents | The distance between the AABB center and the max X and Y values in world space. |
i1 | First intersection point, relative to the AABB center. |
i2 | Second intersection point, relative to the AABB center. |
penetration | The penetration of the line segment along the normal . |
true
if the line segment intersects the AABB and false
otherwise.
|
inlinestatic |
Line segment-AABB intersection test in world space with computation of intersection points and penetration.
p1 | First point that defines the line segment in world space. |
p2 | Second point that defines the line segment in world space. |
aabbCenter | The center of the AABB in world space. |
aabbExtents | The distance between the AABB center and the max X and Y values in world space. |
i1 | First intersection point in world space. |
i2 | Second intersection point in world space. |
penetration | The penetration of the line segment along the closest AABB normal. |
|
inlinestatic |
Line segment-AABB intersection test in the LOCAL space of the AABB with computation of intersection points and penetration.
p1 | First point that defines the line segment, relative to the AABB center. |
p2 | Second point that defines the line segment, relative to the AABB center. |
aabbExtents | The distance between the AABB center and the max X and Y values in world space. |
i1 | First intersection point, relative to the AABB center. |
i2 | Second intersection point, relative to the AABB center. |
penetration | The penetration of the line segment along the closest AABB normal. |
|
inlinestatic |
Line segment-line segment intersection test.
p1 | |
p2 | |
q1 | |
q2 |
|
inlinestatic |
Line segment-line segment intersection test.
p1 | |
p2 | |
q1 | |
q2 | |
point | Point of collision |
distance | Distance along p segment where the collision happens |
|
inlinestatic |
Determines if two lines intersect.
p1 | The starting point of the first line. |
p2 | The ending point of the first line. |
q1 | The starting point of the second line. |
q2 | The ending point of the second line. |
point | The intersection point, if the lines intersect. |
distance | The distance between the intersection point and point p1, if the lines intersect. |
normalizedDist | The normalized distance between the intersection point and point p1, if the lines intersect. |
true
if the lines intersect, false
otherwise.
|
inlinestatic |
Line segment-line segment intersection test.
p1 | |
p2 | |
q1 | |
q2 | |
point | Point of collision |
|
inlinestatic |
Line segment-line segment intersection test. Assumes lines are not colinear nor parallel.
p1 | |
p2 | |
q1 | |
q2 | |
point |
|
inlinestatic |
Returns true
if point is inside centered AABB.
point | |
extents | |
penetration |
|
inlinestatic |
Line segment-circle intersection test.
p1 | |
p2 | |
position | |
radius | |
point |
|
inlinestatic |
Line segment-circle intersection test.
p1 | Start point of the line segment. |
p2 | End point of the line segment. |
position | Position of the center of the circle in world space. |
radius | Radius of the circle. |
ignoreIfStartPointInside | If the intersection should be ignored if the start point of the line segment (p1 ) is inside the circle. |
true
if an intersection is detected. false
otherwise.
|
inlinestatic |
Line segment-circle intersection test.
p1 | Start point of the line segment. |
p2 | End point of the line segment. |
position | Position of the center of the circle in world space. |
radius | Radius of the circle. |
point | Intersection point, if intersecting. Default otherwise. |
ignoreIfStartPointInside | If the intersection should be ignored if the start point of the line segment (p1 ) is inside the circle. |
true
if an intersection is detected. false
otherwise.
|
inlinestatic |
Line segment-circle intersection test.
p1 | Start point of the line segment. |
p2 | End point of the line segment. |
position | Position of the center of the circle in world space. |
radius | Radius of the circle. |
point | Intersection point, if intersecting. Default otherwise. |
normalizedDist | Normalize distance from p1 to p2 of the intersection point, if intersecting. Default otherwise. |
ignoreIfStartPointInside | If the intersection should be ignored if the start point of the line segment (p1 ) is inside the circle. |
true
if an intersection is detected. false
otherwise.
|
inlinestatic |
Circle-polygon intersection test.
circleCenter | |
circleRadius | |
polygonPosition | |
polygonRotationSinInverse | |
polygonRotationCosInverse | |
polygonVertices | |
polygonNormals |
|
inlinestatic |
Circle-polygon intersection test.
circleCenter | |
circleRadius | |
polygonPosition | |
polygonRotation | |
polygonVertices | |
polygonNormals |
|
inlinestatic |
Box-Box (2D) intersection test.
aCenter | |
aExtents | |
aRotation | |
bCenter | |
bExtents | |
bRotation |
|
inlinestatic |
Uses barycentric coordinates to calculate the closest point on a triangle. In conjunction with Fixed Point math this can get quite inaccurate when the triangle become large (more than 100 units) or tiny (less then 0.01 units).
p | Point |
a | Vertex 0 |
b | Vertex 1 |
c | Vertex 2 |
closestPoint | Resulting point on the triangle |
barycentricCoordinates | Barycentric coordinates of the point inside the triangle. |
|
inlinestatic |
Checks if a point is inside the extents of an AABB centered at the origin (local space) and clamp it otherwise.
point | Point in the local space of the AABB. |
aabbExtents | Extents of the AABB. |
clampedPoint | Clamped point inside the AABB. Equals to point if it is already inside the AABB. |
true
if the point is already inside the AABB.
|
inlinestatic |
Calculates the closest point on the line segment defined by two given points to a given point.
point | The point to which the closest point on the segment is calculated. |
a | The first point of the line segment. |
b | The second point of the line segment. |
|
inlinestatic |
Computes the closes point in segment A to a segment B.
segmentStartA | Start point of segment A. |
segmentEndA | End point of segment A. |
segmentStartB | Start point of segment A. |
segmentEndB | End point of segment B. |