Package com.badlogic.gdx.math
Class Intersector
- java.lang.Object
-
- com.badlogic.gdx.math.Intersector
-
public final class Intersector extends java.lang.Object
Class offering various static methods for intersection testing between different geometric objects.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Intersector.MinimumTranslationVector
Minimum translation required to separate two polygons.static class
Intersector.SplitTriangle
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static float
distanceLinePoint(float startX, float startY, float endX, float endY, float pointX, float pointY)
Returns the distance between the given line and point.static float
distanceSegmentPoint(float startX, float startY, float endX, float endY, float pointX, float pointY)
Returns the distance between the given segment and point.static float
distanceSegmentPoint(Vector2 start, Vector2 end, Vector2 point)
Returns the distance between the given segment and point.static boolean
hasOverlap(Vector3[] axes, Vector3[] aVertices, Vector3[] bVertices)
Returns whether two geometries (defined as an array of vertices) have at least one point of intersection using SAT (separating axis theorem)static boolean
intersectBoundsPlaneFast(BoundingBox box, Plane plane)
Quick check whether the givenBoundingBox
andPlane
intersect.static boolean
intersectBoundsPlaneFast(Vector3 center, Vector3 halfDimensions, Vector3 normal, float distance)
Quick check whether the given bounding box and a plane intersect.static boolean
intersectFrustumBounds(Frustum frustum, BoundingBox bounds)
Returns whether the givenFrustum
intersects aBoundingBox
.static boolean
intersectFrustumBounds(Frustum frustum, OrientedBoundingBox obb)
Returns whether the givenFrustum
intersects aOrientedBoundingBox
.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.static boolean
intersectLinePolygon(Vector2 p1, Vector2 p2, Polygon polygon)
Check whether the given line andPolygon
intersect.static boolean
intersectLines(float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4, Vector2 intersection)
Intersects the two lines and returns the intersection point in intersection.static boolean
intersectLines(Vector2 p1, Vector2 p2, Vector2 p3, Vector2 p4, Vector2 intersection)
Intersects the two lines and returns the intersection point in intersection.static boolean
intersectPlanes(Plane a, Plane b, Plane c, Vector3 intersection)
Returns true if the threeplanes
intersect, setting the point of intersection inintersection
, if any.static boolean
intersectPolygonEdges(FloatArray polygon1, FloatArray polygon2)
Returns true if the lines of the specified poygons intersect.static boolean
intersectPolygons(Polygon p1, Polygon p2, Polygon overlap)
Intersects two convex polygons with clockwise vertices and sets the overlap polygon resulting from the intersection.static boolean
intersectPolygons(FloatArray polygon1, FloatArray polygon2)
Returns true if the specified poygons intersect.static boolean
intersectRayBounds(Ray ray, BoundingBox box, Vector3 intersection)
Intersects aRay
and aBoundingBox
, returning the intersection point in intersection.static boolean
intersectRayBoundsFast(Ray ray, BoundingBox box)
Quick check whether the givenRay
andBoundingBox
intersect.static boolean
intersectRayBoundsFast(Ray ray, Vector3 center, Vector3 dimensions)
Quick check whether the givenRay
andBoundingBox
intersect.static boolean
intersectRayOrientedBounds(Ray ray, BoundingBox bounds, Matrix4 transform, Vector3 intersection)
Check whether the givenRay
andOrientedBoundingBox
intersect.static boolean
intersectRayOrientedBounds(Ray ray, OrientedBoundingBox obb, Vector3 intersection)
Check whether the givenRay
andOrientedBoundingBox
intersect.static boolean
intersectRayOrientedBoundsFast(Ray ray, BoundingBox bounds, Matrix4 transform)
Check whether the givenRay
and OrientedBoundingBox
intersect.static boolean
intersectRayOrientedBoundsFast(Ray ray, OrientedBoundingBox obb)
Check whether the givenRay
andOrientedBoundingBox
intersect.static boolean
intersectRayPlane(Ray ray, Plane plane, Vector3 intersection)
static float
intersectRayRay(Vector2 start1, Vector2 direction1, Vector2 start2, Vector2 direction2)
Intersect two 2D Rays and return the scalar parameter of the first ray at the intersection point.static boolean
intersectRaySphere(Ray ray, Vector3 center, float radius, Vector3 intersection)
Intersects aRay
and a sphere, returning the intersection point in intersection.static boolean
intersectRayTriangle(Ray ray, Vector3 t1, Vector3 t2, Vector3 t3, Vector3 intersection)
Intersect aRay
and a triangle, returning the intersection point in intersection.static boolean
intersectRayTriangles(Ray ray, float[] vertices, short[] indices, int vertexSize, Vector3 intersection)
Intersects the given ray with list of triangles.static boolean
intersectRayTriangles(Ray ray, float[] triangles, Vector3 intersection)
Intersects the given ray with list of triangles.static boolean
intersectRayTriangles(Ray ray, java.util.List<Vector3> triangles, Vector3 intersection)
Intersects the given ray with list of triangles.static boolean
intersectRectangles(Rectangle rectangle1, Rectangle rectangle2, Rectangle intersection)
Determines whether the given rectangles intersect and, if they do, sets the suppliedintersection
rectangle to the area of overlap.static boolean
intersectSegmentCircle(Vector2 start, Vector2 end, Circle circle, Intersector.MinimumTranslationVector mtv)
Returns whether the given line segment intersects the given circle.static boolean
intersectSegmentCircle(Vector2 start, Vector2 end, Vector2 center, float squareRadius)
Returns whether the given line segment intersects the given circle.static boolean
intersectSegmentPlane(Vector3 start, Vector3 end, Plane plane, Vector3 intersection)
static boolean
intersectSegmentPolygon(Vector2 p1, Vector2 p2, Polygon polygon)
Check whether the given line segment andPolygon
intersect.static boolean
intersectSegmentRectangle(float startX, float startY, float endX, float endY, Rectangle rectangle)
Determines whether the given rectangle and segment intersectstatic boolean
intersectSegmentRectangle(Vector2 start, Vector2 end, Rectangle rectangle)
static boolean
intersectSegments(float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4, Vector2 intersection)
static boolean
intersectSegments(Vector2 p1, Vector2 p2, Vector2 p3, Vector2 p4, Vector2 intersection)
Intersects the two line segments and returns the intersection point in intersection.static boolean
isPointInPolygon(float[] polygon, int offset, int count, float x, float y)
Returns true if the specified point is in the polygon.static boolean
isPointInPolygon(Array<Vector2> polygon, Vector2 point)
Checks whether the given point is in the polygon.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.static boolean
isPointInTriangle(Vector2 p, Vector2 a, Vector2 b, Vector2 c)
Returns true if the given point is inside the triangle.static boolean
isPointInTriangle(Vector3 point, Vector3 t1, Vector3 t2, Vector3 t3)
Returns whether the given point is inside the triangle.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.static Vector2
nearestSegmentPoint(Vector2 start, Vector2 end, Vector2 point, Vector2 nearest)
Returns a point on the segment nearest to the specified point.static boolean
overlapConvexPolygons(float[] verts1, float[] verts2, Intersector.MinimumTranslationVector mtv)
static boolean
overlapConvexPolygons(float[] verts1, int offset1, int count1, float[] verts2, int offset2, int count2, Intersector.MinimumTranslationVector mtv)
Check whether polygons defined by the given vertex arrays overlap (clockwise or counter-clockwise wound doesn't matter).static boolean
overlapConvexPolygons(Polygon p1, Polygon p2)
Check whether specified convex polygons overlap (clockwise or counter-clockwise wound doesn't matter).static boolean
overlapConvexPolygons(Polygon p1, Polygon p2, Intersector.MinimumTranslationVector mtv)
Check whether convex polygons overlap (clockwise or counter-clockwise wound doesn't matter).static boolean
overlaps(Circle c1, Circle c2)
static boolean
overlaps(Circle c, Rectangle r)
static boolean
overlaps(Rectangle r1, Rectangle r2)
static int
pointLineSide(float linePoint1X, float linePoint1Y, float linePoint2X, float linePoint2Y, float pointX, float pointY)
static int
pointLineSide(Vector2 linePoint1, Vector2 linePoint2, Vector2 point)
Determines on which side of the given line the point is.static void
splitTriangle(float[] triangle, Plane plane, Intersector.SplitTriangle split)
Splits the triangle by the plane.
-
-
-
Method Detail
-
isPointInTriangle
public static boolean isPointInTriangle(Vector3 point, Vector3 t1, Vector3 t2, Vector3 t3)
Returns whether the given point is inside the triangle. This assumes that the point is on the plane of the triangle. No check is performed that this is the case.
If the Vector3 parameters contain both small and large values, such as one that contains 0.0001 and one that contains 10000000.0, this can fail due to floating-point imprecision.- Parameters:
t1
- the first vertex of the trianglet2
- the second vertex of the trianglet3
- the third vertex of the triangle- Returns:
- whether the point is in the triangle
-
isPointInTriangle
public static boolean isPointInTriangle(Vector2 p, Vector2 a, Vector2 b, Vector2 c)
Returns true if the given point is inside the triangle.
-
isPointInTriangle
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.
-
intersectSegmentPlane
public static boolean intersectSegmentPlane(Vector3 start, Vector3 end, Plane plane, Vector3 intersection)
-
pointLineSide
public static int pointLineSide(Vector2 linePoint1, Vector2 linePoint2, Vector2 point)
Determines on which side of the given line the point is. Returns 1 if the point is on the left side of the line, 0 if the point is on the line and -1 if the point is on the right side of the line. Left and right are relative to the lines direction which is linePoint1 to linePoint2.
-
pointLineSide
public static int pointLineSide(float linePoint1X, float linePoint1Y, float linePoint2X, float linePoint2Y, float pointX, float pointY)
-
isPointInPolygon
public static boolean isPointInPolygon(Array<Vector2> polygon, Vector2 point)
Checks whether the given point is in the polygon.- Parameters:
polygon
- The polygon vertices passed as an array- Returns:
- true if the point is in the polygon
-
isPointInPolygon
public static boolean isPointInPolygon(float[] polygon, int offset, int count, float x, float y)
Returns true if the specified point is in the polygon.- Parameters:
offset
- Starting polygon index.count
- Number of array indices to use after offset.
-
intersectPolygons
public static boolean intersectPolygons(Polygon p1, Polygon p2, Polygon overlap)
Intersects two convex polygons with clockwise vertices and sets the overlap polygon resulting from the intersection. Follows the Sutherland-Hodgman algorithm.- Parameters:
p1
- The polygon that is being clippedp2
- The clip polygonoverlap
- The intersection of the two polygons (can be null, if an intersection polygon is not needed)- Returns:
- Whether the two polygons intersect.
-
intersectPolygons
public static boolean intersectPolygons(FloatArray polygon1, FloatArray polygon2)
Returns true if the specified poygons intersect.
-
intersectPolygonEdges
public static boolean intersectPolygonEdges(FloatArray polygon1, FloatArray polygon2)
Returns true if the lines of the specified poygons intersect.
-
distanceLinePoint
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. Note the specified line is not a line segment.
-
distanceSegmentPoint
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.
-
distanceSegmentPoint
public static float distanceSegmentPoint(Vector2 start, Vector2 end, Vector2 point)
Returns the distance between the given segment and point.
-
nearestSegmentPoint
public static Vector2 nearestSegmentPoint(Vector2 start, Vector2 end, Vector2 point, Vector2 nearest)
Returns a point on the segment nearest to the specified point.
-
nearestSegmentPoint
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.
-
intersectSegmentCircle
public static boolean intersectSegmentCircle(Vector2 start, Vector2 end, Vector2 center, float squareRadius)
Returns whether the given line segment intersects the given circle.- Parameters:
start
- The start point of the line segmentend
- The end point of the line segmentcenter
- The center of the circlesquareRadius
- The squared radius of the circle- Returns:
- Whether the line segment and the circle intersect
-
intersectSegmentCircle
public static boolean intersectSegmentCircle(Vector2 start, Vector2 end, Circle circle, Intersector.MinimumTranslationVector mtv)
Returns whether the given line segment intersects the given circle.- Parameters:
start
- The start point of the line segmentend
- The end point of the line segmentcircle
- The circlemtv
- A Minimum Translation Vector to fill in the case of a collision, or null (optional).- Returns:
- Whether the line segment and the circle intersect
-
intersectFrustumBounds
public static boolean intersectFrustumBounds(Frustum frustum, BoundingBox bounds)
Returns whether the givenFrustum
intersects aBoundingBox
.- Parameters:
frustum
- The frustumbounds
- The bounding box- Returns:
- Whether the frustum intersects the bounding box
-
intersectFrustumBounds
public static boolean intersectFrustumBounds(Frustum frustum, OrientedBoundingBox obb)
Returns whether the givenFrustum
intersects aOrientedBoundingBox
.- Parameters:
frustum
- The frustumobb
- The oriented bounding box- Returns:
- Whether the frustum intersects the oriented bounding box
-
intersectRayRay
public static float intersectRayRay(Vector2 start1, Vector2 direction1, Vector2 start2, Vector2 direction2)
Intersect two 2D Rays and return the scalar parameter of the first ray at the intersection point. You can get the intersection point by: Vector2 point(direction1).scl(scalar).add(start1); For more information, check: http://stackoverflow.com/a/565282/1091440- Parameters:
start1
- Where the first ray startdirection1
- The direction the first ray is pointingstart2
- Where the second ray startdirection2
- The direction the second ray is pointing- 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.
-
intersectRayPlane
public static boolean intersectRayPlane(Ray ray, Plane plane, Vector3 intersection)
Intersects aRay
and aPlane
. The intersection point is stored in intersection in case an intersection is present.- Parameters:
intersection
- The vector the intersection point is written to (optional)- Returns:
- Whether an intersection is present.
-
intersectLinePlane
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. The intersection is returned as the distance from the first point to the plane. In case an intersection happened, the return value is in the range [0,1]. The intersection point can be recovered by point1 + t * (point2 - point1) where t is the return value of this method.
-
intersectPlanes
public static boolean intersectPlanes(Plane a, Plane b, Plane c, Vector3 intersection)
Returns true if the threeplanes
intersect, setting the point of intersection inintersection
, if any.- Parameters:
intersection
- The point where the three planes intersect
-
intersectRayTriangle
public static boolean intersectRayTriangle(Ray ray, Vector3 t1, Vector3 t2, Vector3 t3, Vector3 intersection)
Intersect aRay
and a triangle, returning the intersection point in intersection.- Parameters:
t1
- The first vertex of the trianglet2
- The second vertex of the trianglet3
- The third vertex of the triangleintersection
- The intersection point (optional)- Returns:
- True in case an intersection is present.
-
intersectRaySphere
public static boolean intersectRaySphere(Ray ray, Vector3 center, float radius, Vector3 intersection)
Intersects aRay
and a sphere, returning the intersection point in intersection.- Parameters:
ray
- The ray, the direction component must be normalized before calling this methodcenter
- The center of the sphereradius
- The radius of the sphereintersection
- The intersection point (optional, can be null)- Returns:
- Whether an intersection is present.
-
intersectRayBounds
public static boolean intersectRayBounds(Ray ray, BoundingBox box, Vector3 intersection)
Intersects aRay
and aBoundingBox
, returning the intersection point in intersection. This intersection is defined as the point on the ray closest to the origin which is within the specified bounds.The returned intersection (if any) is guaranteed to be within the bounds of the bounding box, but it can occasionally diverge slightly from ray, due to small floating-point errors.
If the origin of the ray is inside the box, this method returns true and the intersection point is set to the origin of the ray, accordingly to the definition above.
- Parameters:
intersection
- The intersection point (optional)- Returns:
- Whether an intersection is present.
-
intersectRayBoundsFast
public static boolean intersectRayBoundsFast(Ray ray, BoundingBox box)
Quick check whether the givenRay
andBoundingBox
intersect.- Returns:
- Whether the ray and the bounding box intersect.
-
intersectRayBoundsFast
public static boolean intersectRayBoundsFast(Ray ray, Vector3 center, Vector3 dimensions)
Quick check whether the givenRay
andBoundingBox
intersect.- Parameters:
center
- The center of the bounding boxdimensions
- The dimensions (width, height and depth) of the bounding box- Returns:
- Whether the ray and the bounding box intersect.
-
intersectRayOrientedBoundsFast
public static boolean intersectRayOrientedBoundsFast(Ray ray, OrientedBoundingBox obb)
Check whether the givenRay
andOrientedBoundingBox
intersect.- Returns:
- Whether the ray and the oriented bounding box intersect.
-
intersectRayOrientedBoundsFast
public static boolean intersectRayOrientedBoundsFast(Ray ray, BoundingBox bounds, Matrix4 transform)
Check whether the givenRay
and OrientedBoundingBox
intersect.- Parameters:
transform
- - the BoundingBox transformation- Returns:
- Whether the ray and the oriented bounding box intersect.
-
intersectRayOrientedBounds
public static boolean intersectRayOrientedBounds(Ray ray, OrientedBoundingBox obb, Vector3 intersection)
Check whether the givenRay
andOrientedBoundingBox
intersect.- Parameters:
intersection
- The intersection point (optional)- Returns:
- Whether an intersection is present.
-
intersectRayOrientedBounds
public static boolean intersectRayOrientedBounds(Ray ray, BoundingBox bounds, Matrix4 transform, Vector3 intersection)
Check whether the givenRay
andOrientedBoundingBox
intersect. Based on code at: https://github.com/opengl-tutorials/ogl/blob/master/misc05_picking/misc05_picking_custom.cpp#L83- Parameters:
intersection
- The intersection point (optional)- Returns:
- Whether an intersection is present.
-
intersectRayTriangles
public static boolean intersectRayTriangles(Ray ray, float[] triangles, Vector3 intersection)
Intersects the given ray with list of triangles. Returns the nearest intersection point in intersection- Parameters:
triangles
- The triangles, each successive 9 elements are the 3 vertices of a triangle, a vertex is made of 3 successive floats (XYZ)intersection
- The nearest intersection point (optional)- Returns:
- Whether the ray and the triangles intersect.
-
intersectRayTriangles
public static boolean intersectRayTriangles(Ray ray, float[] vertices, short[] indices, int vertexSize, Vector3 intersection)
Intersects the given ray with list of triangles. Returns the nearest intersection point in intersection- Parameters:
indices
- the indices, each successive 3 shorts index the 3 vertices of a trianglevertexSize
- the size of a vertex in floatsintersection
- The nearest intersection point (optional)- Returns:
- Whether the ray and the triangles intersect.
-
intersectRayTriangles
public static boolean intersectRayTriangles(Ray ray, java.util.List<Vector3> triangles, Vector3 intersection)
Intersects the given ray with list of triangles. Returns the nearest intersection point in intersection- Parameters:
triangles
- The triangles, each successive 3 elements are the 3 vertices of a triangleintersection
- The nearest intersection point (optional)- Returns:
- Whether the ray and the triangles intersect.
-
intersectBoundsPlaneFast
public static boolean intersectBoundsPlaneFast(BoundingBox box, Plane plane)
Quick check whether the givenBoundingBox
andPlane
intersect.- Returns:
- Whether the bounding box and the plane intersect.
-
intersectBoundsPlaneFast
public static boolean intersectBoundsPlaneFast(Vector3 center, Vector3 halfDimensions, Vector3 normal, float distance)
Quick check whether the given bounding box and a plane intersect. Code adapted from Christer Ericson's Real Time Collision- Parameters:
center
- The center of the bounding boxhalfDimensions
- Half of the dimensions (width, height and depth) of the bounding boxnormal
- The normal of the planedistance
- The distance of the plane- Returns:
- Whether the bounding box and the plane intersect.
-
intersectLines
public static boolean intersectLines(Vector2 p1, Vector2 p2, Vector2 p3, Vector2 p4, Vector2 intersection)
Intersects the two lines and returns the intersection point in intersection.- Parameters:
p1
- The first point of the first linep2
- The second point of the first linep3
- The first point of the second linep4
- The second point of the second lineintersection
- The intersection point. May be null.- Returns:
- Whether the two lines intersect
-
intersectLines
public static boolean intersectLines(float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4, Vector2 intersection)
Intersects the two lines and returns the intersection point in intersection.- Parameters:
intersection
- The intersection point, or null.- Returns:
- Whether the two lines intersect
-
intersectLinePolygon
public static boolean intersectLinePolygon(Vector2 p1, Vector2 p2, Polygon polygon)
Check whether the given line andPolygon
intersect.- Parameters:
p1
- The first point of the linep2
- The second point of the line- Returns:
- Whether polygon and line intersects
-
intersectRectangles
public static boolean intersectRectangles(Rectangle rectangle1, Rectangle rectangle2, Rectangle intersection)
Determines whether the given rectangles intersect and, if they do, sets the suppliedintersection
rectangle to the area of overlap.- Returns:
- Whether the rectangles intersect
-
intersectSegmentRectangle
public static boolean intersectSegmentRectangle(float startX, float startY, float endX, float endY, Rectangle rectangle)
Determines whether the given rectangle and segment intersect- Parameters:
startX
- x-coordinate start of line segmentstartY
- y-coordinate start of line segmentendX
- y-coordinate end of line segmentendY
- y-coordinate end of line segmentrectangle
- rectangle that is being tested for collision- Returns:
- whether the rectangle intersects with the line segment
-
intersectSegmentRectangle
public static boolean intersectSegmentRectangle(Vector2 start, Vector2 end, Rectangle rectangle)
-
intersectSegmentPolygon
public static boolean intersectSegmentPolygon(Vector2 p1, Vector2 p2, Polygon polygon)
Check whether the given line segment andPolygon
intersect.- Parameters:
p1
- The first point of the segmentp2
- The second point of the segment- Returns:
- Whether polygon and segment intersect
-
intersectSegments
public static boolean intersectSegments(Vector2 p1, Vector2 p2, Vector2 p3, Vector2 p4, Vector2 intersection)
Intersects the two line segments and returns the intersection point in intersection.- Parameters:
p1
- The first point of the first line segmentp2
- The second point of the first line segmentp3
- The first point of the second line segmentp4
- The second point of the second line segmentintersection
- The intersection point. May be null.- Returns:
- Whether the two line segments intersect
-
intersectSegments
public static boolean intersectSegments(float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4, Vector2 intersection)
- Parameters:
intersection
- May be null.
-
overlapConvexPolygons
public static boolean overlapConvexPolygons(Polygon p1, Polygon p2)
Check whether specified convex polygons overlap (clockwise or counter-clockwise wound doesn't matter).- Parameters:
p1
- The first polygon.p2
- The second polygon.- Returns:
- Whether polygons overlap.
-
overlapConvexPolygons
public static boolean overlapConvexPolygons(Polygon p1, Polygon p2, Intersector.MinimumTranslationVector mtv)
Check whether convex polygons overlap (clockwise or counter-clockwise wound doesn't matter). If they do, optionally obtain a Minimum Translation Vector indicating the minimum magnitude vector required to push the polygon p1 out of collision with polygon p2.- Parameters:
p1
- The first polygon.p2
- The second polygon.mtv
- A Minimum Translation Vector to fill in the case of a collision, or null (optional).- Returns:
- Whether polygons overlap.
-
overlapConvexPolygons
public static boolean overlapConvexPolygons(float[] verts1, float[] verts2, Intersector.MinimumTranslationVector mtv)
-
overlapConvexPolygons
public static boolean overlapConvexPolygons(float[] verts1, int offset1, int count1, float[] verts2, int offset2, int count2, Intersector.MinimumTranslationVector mtv)
Check whether polygons defined by the given vertex arrays overlap (clockwise or counter-clockwise wound doesn't matter). If they do, optionally obtain a Minimum Translation Vector indicating the minimum magnitude vector required to push the polygon defined by verts1 out of the collision with the polygon defined by verts2.- Parameters:
verts1
- Vertices of the first polygon.offset1
- the offset of the verts1 arraycount1
- the amount that is added to the offset1verts2
- Vertices of the second polygon.offset2
- the offset of the verts2 arraycount2
- the amount that is added to the offset2mtv
- A Minimum Translation Vector to fill in the case of a collision, or null (optional).- Returns:
- Whether polygons overlap.
-
splitTriangle
public static void splitTriangle(float[] triangle, Plane plane, Intersector.SplitTriangle split)
Splits the triangle by the plane. The result is stored in the SplitTriangle instance. Depending on where the triangle is relative to the plane, the result can be:- Triangle is fully in front/behind:
Intersector.SplitTriangle.front
orIntersector.SplitTriangle.back
will contain the original triangle,Intersector.SplitTriangle.total
will be one. - Triangle has two vertices in front, one behind:
Intersector.SplitTriangle.front
contains 2 triangles,Intersector.SplitTriangle.back
contains 1 triangles,Intersector.SplitTriangle.total
will be 3. - Triangle has one vertex in front, two behind:
Intersector.SplitTriangle.front
contains 1 triangle,Intersector.SplitTriangle.back
contains 2 triangles,Intersector.SplitTriangle.total
will be 3.
- Parameters:
split
- output SplitTriangle
- Triangle is fully in front/behind:
-
hasOverlap
public static boolean hasOverlap(Vector3[] axes, Vector3[] aVertices, Vector3[] bVertices)
Returns whether two geometries (defined as an array of vertices) have at least one point of intersection using SAT (separating axis theorem)- Parameters:
axes
- - Axes to be testedaVertices
- - Vertices from geometry AbVertices
- - Vertices from geometry B- Returns:
- if geometries are intersecting
-
-