APIdia Launch Partner
Top Description Inners Fields Constructors Methods
com.badlogic.gdx.math

public final Class Intersector

extends Object
Class Inheritance
Imports
com.badlogic.gdx.math.Plane.PlaneSide, com.badlogic.gdx.math.collision.BoundingBox, .OrientedBoundingBox, .Ray, com.badlogic.gdx.utils.Array, .FloatArray, java.util.Arrays, .List

Class offering various static methods for intersection testing between different geometric objects.
Authors
[email protected], jan.stria, Nathan Sweet

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
Intersector.MinimumTranslationVector

Minimum translation required to separate two polygons.

public static class

Field Summary

Modifier and TypeField and Description
pack-priv static Vector3
private static final Vector3
private static final Vector2
e

private static final Vector2
private static final Vector2
private static final FloatArray
private static final FloatArray
private static final Vector3
i

pack-priv static Vector3
private static final Vector2
private static final Plane
p

private static final Vector2
s

private static final Vector3
pack-priv static Vector3
pack-priv static Vector3
pack-priv static Vector3
pack-priv static Vector3
private static final Vector3
private static final Vector3
private static final Vector3
pack-priv static Vector2
pack-priv static Vector2
pack-priv static Vector2
pack-priv static Vector2

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
pack-priv static float
det(float a, float b, float c, float d)

pack-priv static double
detd(double a, double b, double c, double d)

public static float
distanceLinePoint(float startX, float startY, float endX, float endY, float pointX, float pointY)

Returns the distance between the given line and point.

public static float
distanceSegmentPoint(float startX, float startY, float endX, float endY, float pointX, float pointY)

Returns the distance between the given segment and point.

public static float
distanceSegmentPoint(Vector2 start, Vector2 end, Vector2 point)

Returns the distance between the given segment and point.

public static boolean

Returns:

if geometries are intersecting
hasOverlap
(Vector3[]
- Axes to be tested
axes
,
Vector3[]
- Vertices from geometry A
aVertices
,
Vector3[]
- Vertices from geometry B
bVertices
)

Returns whether two geometries (defined as an array of vertices) have at least one point of intersection using SAT (separating axis theorem)

public static boolean

Returns:

Whether the bounding box and the plane intersect.
intersectBoundsPlaneFast
(BoundingBox box, Plane plane)

Quick check whether the given BoundingBox and Plane intersect.

public static boolean

Returns:

Whether the bounding box and the plane intersect.
intersectBoundsPlaneFast
(Vector3
The center of the bounding box
center
,
Vector3
Half of the dimensions (width, height and depth) of the bounding box
halfDimensions
,
Vector3
The normal of the plane
normal
,
float
The distance of the plane
distance
)

Quick check whether the given bounding box and a plane intersect.

public static boolean

Returns:

Whether the frustum intersects the bounding box
intersectFrustumBounds
(Frustum
The frustum
frustum
,
BoundingBox
The bounding box
bounds
)

Returns whether the given Frustum intersects a BoundingBox.

public static boolean

Returns:

Whether the frustum intersects the oriented bounding box
intersectFrustumBounds
(Frustum
The frustum
frustum
,
OrientedBoundingBox
The oriented bounding box
obb
)

Returns whether the given Frustum intersects a OrientedBoundingBox.

public static float
intersectLinePlane(float x, float y, float z, float x2, float y2, float z2, Plane plane, Vector3 intersection)

Intersects a line and a plane.

public static boolean

Returns:

Whether polygon and line intersects
intersectLinePolygon
(Vector2
The first point of the line
p1
,
Vector2
The second point of the line
p2
,
Polygon polygon)

Check whether the given line and Polygon intersect.

public static boolean

Returns:

Whether the two lines intersect
intersectLines
(Vector2
The first point of the first line
p1
,
Vector2
The second point of the first line
p2
,
Vector2
The first point of the second line
p3
,
Vector2
The second point of the second line
p4
,
Vector2
The intersection point. May be null.
intersection
)

Intersects the two lines and returns the intersection point in intersection.

public static boolean

Returns:

Whether the two lines intersect
intersectLines
(float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4, Vector2
The intersection point, or null.
intersection
)

Intersects the two lines and returns the intersection point in intersection.

public static boolean
intersectPlanes(Plane a, Plane b, Plane c, Vector3
The point where the three planes intersect
intersection
)

Returns true if the three planes intersect, setting the point of intersection in intersection, if any.

public static boolean
intersectPolygonEdges(FloatArray polygon1, FloatArray polygon2)

Returns true if the lines of the specified polygons intersect.

public static boolean

Returns:

Whether the two polygons intersect.
intersectPolygons
(Polygon
The polygon that is being clipped
p1
,
Polygon
The clip polygon
p2
,
Polygon
The intersection of the two polygons (can be null, if an intersection polygon is not needed)
overlap
)

Intersects two convex polygons with clockwise vertices and sets the overlap polygon resulting from the intersection.

public static boolean
intersectPolygons(FloatArray polygon1, FloatArray polygon2)

Returns true if the specified polygons intersect.

public static boolean

Returns:

Whether an intersection is present.
intersectRayBounds
(Ray ray, BoundingBox box, Vector3
The intersection point (optional)
intersection
)

Intersects a Ray and a BoundingBox, returning the intersection point in intersection.

public static boolean

Returns:

Whether the ray and the bounding box intersect.
intersectRayBoundsFast
(Ray ray, BoundingBox box)

Quick check whether the given Ray and BoundingBox intersect.

public static boolean

Returns:

Whether the ray and the bounding box intersect.
intersectRayBoundsFast
(Ray ray, Vector3
The center of the bounding box
center
,
Vector3
The dimensions (width, height and depth) of the bounding box
dimensions
)

Quick check whether the given Ray and BoundingBox intersect.

public static boolean

Returns:

Whether an intersection is present.
intersectRayOrientedBounds
(Ray ray, OrientedBoundingBox obb, Vector3
The intersection point (optional)
intersection
)

Check whether the given Ray and OrientedBoundingBox intersect.

public static boolean

Returns:

Whether an intersection is present.
intersectRayOrientedBounds
(Ray ray, BoundingBox bounds, Matrix4 transform, Vector3
The intersection point (optional)
intersection
)

Check whether the given Ray and OrientedBoundingBox intersect.

public static boolean

Returns:

Whether the ray and the oriented bounding box intersect.
intersectRayOrientedBoundsFast
(Ray ray, OrientedBoundingBox obb)

Check whether the given Ray and OrientedBoundingBox intersect.

public static boolean

Returns:

Whether the ray and the oriented bounding box intersect.
intersectRayOrientedBoundsFast
(Ray ray, BoundingBox bounds, Matrix4
- the BoundingBox transformation
transform
)

Check whether the given Ray and Oriented BoundingBox intersect.

public static boolean

Returns:

Whether an intersection is present.
intersectRayPlane
(Ray ray, Plane plane, Vector3
The vector the intersection point is written to (optional)
intersection
)

Intersects a Ray and a Plane.

public static float

Returns:

scalar parameter on the first ray describing the point where the intersection happens. May be negative. In case the rays are collinear, Float.POSITIVE_INFINITY will be returned.
intersectRayRay
(Vector2
Where the first ray start
start1
,
Vector2
The direction the first ray is pointing
direction1
,
Vector2
Where the second ray start
start2
,
Vector2
The direction the second ray is pointing
direction2
)

Intersect two 2D Rays and return the scalar parameter of the first ray at the intersection point.

public static boolean

Returns:

Whether an intersection is present.
intersectRaySphere
(Ray
The ray, the direction component must be normalized before calling this method
ray
,
Vector3
The center of the sphere
center
,
float
The radius of the sphere
radius
,
Vector3
The intersection point (optional, can be null)
intersection
)

Intersects a Ray and a sphere, returning the intersection point in intersection.

public static boolean

Returns:

True in case an intersection is present.
intersectRayTriangle
(Ray ray, Vector3
The first vertex of the triangle
t1
,
Vector3
The second vertex of the triangle
t2
,
Vector3
The third vertex of the triangle
t3
,
Vector3
The intersection point (optional)
intersection
)

Intersect a Ray and a triangle, returning the intersection point in intersection.

public static boolean

Returns:

Whether the ray and the triangles intersect.
intersectRayTriangles
(Ray ray, float[]
The triangles, each successive 9 elements are the 3 vertices of a triangle, a vertex is made of 3 successive floats (XYZ)
triangles
,
Vector3
The nearest intersection point (optional)
intersection
)

Intersects the given ray with list of triangles.

public static boolean

Returns:

Whether the ray and the triangles intersect.
intersectRayTriangles
(Ray ray, float[] vertices, short[]
the indices, each successive 3 shorts index the 3 vertices of a triangle
indices
,
int
the size of a vertex in floats
vertexSize
,
Vector3
The nearest intersection point (optional)
intersection
)

Intersects the given ray with list of triangles.

public static boolean

Returns:

Whether the ray and the triangles intersect.
intersectRayTriangles
(Ray ray, List<Vector3>
The triangles, each successive 3 elements are the 3 vertices of a triangle
triangles
,
Vector3
The nearest intersection point (optional)
intersection
)

Intersects the given ray with list of triangles.

public static boolean

Returns:

Whether the rectangles intersect
intersectRectangles
(Rectangle rectangle1, Rectangle rectangle2, Rectangle intersection)

Determines whether the given rectangles intersect and, if they do, sets the supplied intersection rectangle to the area of overlap.

public static boolean

Returns:

Whether the line segment and the circle intersect
intersectSegmentCircle
(Vector2
The start point of the line segment
start
,
Vector2
The end point of the line segment
end
,
Vector2
The center of the circle
center
,
float
The squared radius of the circle
squareRadius
)

Returns whether the given line segment intersects the given circle.

public static boolean

Returns:

Whether the line segment and the circle intersect
intersectSegmentCircle
(Vector2
The start point of the line segment
start
,
Vector2
The end point of the line segment
end
,
Circle
The circle
circle
,
Intersector.MinimumTranslationVector
A Minimum Translation Vector to fill in the case of a collision, or null (optional).
mtv
)

Returns whether the given line segment intersects the given circle.

public static boolean
intersectSegmentPlane(Vector3 start, Vector3 end, Plane plane, Vector3 intersection)

public static boolean

Returns:

Whether polygon and segment intersect
intersectSegmentPolygon
(Vector2
The first point of the segment
p1
,
Vector2
The second point of the segment
p2
,
Polygon polygon)

Check whether the given line segment and Polygon intersect.

public static boolean

Returns:

whether the rectangle intersects with the line segment
intersectSegmentRectangle
(float
x-coordinate start of line segment
startX
,
float
y-coordinate start of line segment
startY
,
float
y-coordinate end of line segment
endX
,
float
y-coordinate end of line segment
endY
,
Rectangle
rectangle that is being tested for collision
rectangle
)

Determines whether the given rectangle and segment intersect

public static boolean
public static boolean

Returns:

Whether the two line segments intersect
intersectSegments
(Vector2
The first point of the first line segment
p1
,
Vector2
The second point of the first line segment
p2
,
Vector2
The first point of the second line segment
p3
,
Vector2
The second point of the second line segment
p4
,
Vector2
The intersection point. May be null.
intersection
)

Intersects the two line segments and returns the intersection point in intersection.

public static boolean
intersectSegments(float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4, Vector2
May be null.
intersection
)

public static boolean

Returns:

true if the point is in the polygon
isPointInPolygon
(Array<Vector2>
The polygon vertices passed as an array
polygon
,
Vector2 point)

Checks whether the given point is in the polygon.

public static boolean
isPointInPolygon(float[] polygon, int
Starting polygon index.
offset
,
int
Number of array indices to use after offset.
count
,
float x, float y)

Returns true if the specified point is in the polygon.

public static boolean

Returns:

whether the point is in the triangle
isPointInTriangle
(Vector3 point, Vector3
the first vertex of the triangle
t1
,
Vector3
the second vertex of the triangle
t2
,
Vector3
the third vertex of the triangle
t3
)

Returns whether the given point is inside the triangle.

public static boolean
isPointInTriangle(Vector2 p, Vector2 a, Vector2 b, Vector2 c)

Returns true if the given point is inside the triangle.

public static boolean
isPointInTriangle(float px, float py, float ax, float ay, float bx, float by, float cx, float cy)

Returns true if the given point is inside the triangle.

public static Vector2
nearestSegmentPoint(Vector2 start, Vector2 end, Vector2 point, Vector2 nearest)

Returns a point on the segment nearest to the specified point.

public static Vector2
nearestSegmentPoint(float startX, float startY, float endX, float endY, float pointX, float pointY, Vector2 nearest)

Returns a point on the segment nearest to the specified point.

public static boolean

Returns:

Whether polygons overlap.
overlapConvexPolygons
(Polygon
The first polygon.
p1
,
Polygon
The second polygon.
p2
)

Check whether specified convex polygons overlap (clockwise or counter-clockwise wound doesn't matter).

public static boolean

Returns:

Whether polygons overlap.
overlapConvexPolygons
(Polygon
The first polygon.
p1
,
Polygon
The second polygon.
p2
,
Intersector.MinimumTranslationVector
A Minimum Translation Vector to fill in the case of a collision, or null (optional).
mtv
)

Check whether convex polygons overlap (clockwise or counter-clockwise wound doesn't matter).

public static boolean
overlapConvexPolygons(float[] verts1, float[] verts2, Intersector.MinimumTranslationVector mtv)

public static boolean

Returns:

Whether polygons overlap.
overlapConvexPolygons
(float[]
Vertices of the first polygon.
verts1
,
int
the offset of the verts1 array
offset1
,
int
the amount that is added to the offset1
count1
,
float[]
Vertices of the second polygon.
verts2
,
int
the offset of the verts2 array
offset2
,
int
the amount that is added to the offset2
count2
,
Intersector.MinimumTranslationVector
A Minimum Translation Vector to fill in the case of a collision, or null (optional).
mtv
)

Check whether polygons defined by the given vertex arrays overlap (clockwise or counter-clockwise wound doesn't matter).

public static boolean
public static boolean
public static boolean
private static boolean
overlapsOnAxisOfShape(float[] verts1, int
offset of verts1
offset1
,
int
count of verts1
count1
,
float[] verts2, int
offset of verts2
offset2
,
int
count of verts2
count2
,
Intersector.MinimumTranslationVector
the minimum translation vector
mtv
,
boolean
states if shape a and b are shifted. Important for calculating the axis translation for verts1.
shapesShifted
)

Implementation of the separating axis theorem (SAT) algorithm

public static int
pointLineSide(Vector2 linePoint1, Vector2 linePoint2, Vector2 point)

Determines on which side of the given line the point is.

public static int
pointLineSide(float linePoint1X, float linePoint1Y, float linePoint2X, float linePoint2Y, float pointX, float pointY)

private static void
splitEdge(float[] vertices, int s, int e, int stride, Plane plane, float[] split, int offset)

public static void
splitTriangle(float[] triangle, Plane plane, Intersector.SplitTriangle
output SplitTriangle
split
)

Splits the triangle by the plane.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait