public final class Intersector extends Object
Modifier and Type | Class and Description |
---|---|
static class |
Intersector.MinimumTranslationVector
Minimum translation required to separate two polygons.
|
static class |
Intersector.SplitTriangle |
Modifier and Type | Method and 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 |
intersectBoundsPlaneFast(BoundingBox box,
Plane plane)
Quick check whether the given
BoundingBox and Plane intersect. |
static boolean |
intersectBoundsPlaneFast(Vector3 center,
Vector3 halfDimensions,
Vector3 normal,
float distance)
Quick check whether the given bounding box and a plane intersect.
|
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 and
Polygon 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 three
planes intersect, setting the point of intersection in intersection , if any. |
static boolean |
intersectPolygonEdges(FloatArray polygon1,
FloatArray polygon2)
Returns true if the lines of the specified poygons intersect.
|
static boolean |
intersectPolygons(FloatArray polygon1,
FloatArray polygon2)
Returns true if 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 |
intersectRayBounds(Ray ray,
BoundingBox box,
Vector3 intersection)
Intersects a
Ray and a BoundingBox , returning the intersection point in intersection. |
static boolean |
intersectRayBoundsFast(Ray ray,
BoundingBox box)
Quick check whether the given
Ray and BoundingBox intersect. |
static boolean |
intersectRayBoundsFast(Ray ray,
Vector3 center,
Vector3 dimensions)
Quick check whether the given
Ray and BoundingBox intersect. |
static boolean |
intersectRayOrientedBoundsFast(Ray ray,
BoundingBox bounds,
Matrix4 matrix)
Quick check whether the given
Ray and Oriented BoundingBox 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 a
Ray and a sphere, returning the intersection point in intersection. |
static boolean |
intersectRayTriangle(Ray ray,
Vector3 t1,
Vector3 t2,
Vector3 t3,
Vector3 intersection)
Intersect a
Ray 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,
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 supplied
intersection 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 and
Polygon intersect. |
static boolean |
intersectSegmentRectangle(float startX,
float startY,
float endX,
float endY,
Rectangle rectangle)
Determines whether the given rectangle and segment intersect
|
static 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(Array<Vector2> polygon,
Vector2 point)
Checks whether the given point is in the polygon.
|
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 |
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.
|
public static boolean isPointInTriangle(Vector3 point, Vector3 t1, Vector3 t2, Vector3 t3)
t1
- the first vertex of the trianglet2
- the second vertex of the trianglet3
- the third vertex of the trianglepublic static boolean isPointInTriangle(Vector2 p, Vector2 a, Vector2 b, Vector2 c)
public static boolean isPointInTriangle(float px, float py, float ax, float ay, float bx, float by, float cx, float cy)
public static boolean intersectSegmentPlane(Vector3 start, Vector3 end, Plane plane, Vector3 intersection)
public static int pointLineSide(Vector2 linePoint1, Vector2 linePoint2, Vector2 point)
public static int pointLineSide(float linePoint1X, float linePoint1Y, float linePoint2X, float linePoint2Y, float pointX, float pointY)
public static boolean isPointInPolygon(Array<Vector2> polygon, Vector2 point)
polygon
- The polygon vertices passed as an arraypublic static boolean isPointInPolygon(float[] polygon, int offset, int count, float x, float y)
offset
- Starting polygon index.count
- Number of array indices to use after offset.public static boolean intersectPolygons(Polygon p1, Polygon p2, Polygon overlap)
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)public static boolean intersectPolygons(FloatArray polygon1, FloatArray polygon2)
public static boolean intersectPolygonEdges(FloatArray polygon1, FloatArray polygon2)
public static float distanceLinePoint(float startX, float startY, float endX, float endY, float pointX, float pointY)
public static float distanceSegmentPoint(float startX, float startY, float endX, float endY, float pointX, float pointY)
public static float distanceSegmentPoint(Vector2 start, Vector2 end, Vector2 point)
public static Vector2 nearestSegmentPoint(Vector2 start, Vector2 end, Vector2 point, Vector2 nearest)
public static Vector2 nearestSegmentPoint(float startX, float startY, float endX, float endY, float pointX, float pointY, Vector2 nearest)
public static boolean intersectSegmentCircle(Vector2 start, Vector2 end, Vector2 center, float squareRadius)
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 circlepublic static boolean intersectSegmentCircle(Vector2 start, Vector2 end, Circle circle, Intersector.MinimumTranslationVector mtv)
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).public static float intersectRayRay(Vector2 start1, Vector2 direction1, Vector2 start2, Vector2 direction2)
start1
- Where the first ray startdirection1
- The direction the first ray is pointingstart2
- Where the second ray startdirection2
- The direction the second ray is pointingpublic static boolean intersectRayPlane(Ray ray, Plane plane, Vector3 intersection)
Ray
and a Plane
. The intersection point is stored in intersection in case an intersection is
present.intersection
- The vector the intersection point is written to (optional)public static float intersectLinePlane(float x, float y, float z, float x2, float y2, float z2, Plane plane, Vector3 intersection)
public static boolean intersectPlanes(Plane a, Plane b, Plane c, Vector3 intersection)
planes
intersect, setting the point of intersection in intersection
, if any.intersection
- The point where the three planes intersectpublic static boolean intersectRayTriangle(Ray ray, Vector3 t1, Vector3 t2, Vector3 t3, Vector3 intersection)
Ray
and a triangle, returning the intersection point in intersection.t1
- The first vertex of the trianglet2
- The second vertex of the trianglet3
- The third vertex of the triangleintersection
- The intersection point (optional)public static boolean intersectRaySphere(Ray ray, Vector3 center, float radius, Vector3 intersection)
Ray
and a sphere, returning the intersection point in intersection.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)public static boolean intersectRayBounds(Ray ray, BoundingBox box, Vector3 intersection)
Ray
and a BoundingBox
, 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.
intersection
- The intersection point (optional)public static boolean intersectRayBoundsFast(Ray ray, BoundingBox box)
Ray
and BoundingBox
intersect.public static boolean intersectRayBoundsFast(Ray ray, Vector3 center, Vector3 dimensions)
Ray
and BoundingBox
intersect.center
- The center of the bounding boxdimensions
- The dimensions (width, height and depth) of the bounding boxpublic static boolean intersectRayOrientedBoundsFast(Ray ray, BoundingBox bounds, Matrix4 matrix)
Ray
and Oriented BoundingBox
intersect.
Based on code at: https://github.com/opengl-tutorials/ogl/blob/master/misc05_picking/misc05_picking_custom.cpp#L83matrix
- The orientation of the bounding boxpublic static boolean intersectRayTriangles(Ray ray, float[] triangles, Vector3 intersection)
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)public static boolean intersectRayTriangles(Ray ray, float[] vertices, short[] indices, int vertexSize, Vector3 intersection)
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)public static boolean intersectRayTriangles(Ray ray, List<Vector3> triangles, Vector3 intersection)
triangles
- The triangles, each successive 3 elements are the 3 vertices of a triangleintersection
- The nearest intersection point (optional)public static boolean intersectBoundsPlaneFast(BoundingBox box, Plane plane)
BoundingBox
and Plane
intersect.public static boolean intersectBoundsPlaneFast(Vector3 center, Vector3 halfDimensions, Vector3 normal, float distance)
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 planepublic static boolean intersectLines(Vector2 p1, Vector2 p2, Vector2 p3, Vector2 p4, Vector2 intersection)
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.public static boolean intersectLines(float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4, Vector2 intersection)
intersection
- The intersection point, or null.public static boolean intersectLinePolygon(Vector2 p1, Vector2 p2, Polygon polygon)
Polygon
intersect.p1
- The first point of the linep2
- The second point of the linepublic static boolean intersectRectangles(Rectangle rectangle1, Rectangle rectangle2, Rectangle intersection)
intersection
rectangle to the
area of overlap.public static boolean intersectSegmentRectangle(float startX, float startY, float endX, float endY, Rectangle rectangle)
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 collisionpublic static boolean intersectSegmentRectangle(Vector2 start, Vector2 end, Rectangle rectangle)
public static boolean intersectSegmentPolygon(Vector2 p1, Vector2 p2, Polygon polygon)
Polygon
intersect.p1
- The first point of the segmentp2
- The second point of the segmentpublic static boolean intersectSegments(Vector2 p1, Vector2 p2, Vector2 p3, Vector2 p4, Vector2 intersection)
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.public static boolean intersectSegments(float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4, Vector2 intersection)
intersection
- May be null.public static boolean overlapConvexPolygons(Polygon p1, Polygon p2)
p1
- The first polygon.p2
- The second polygon.public static boolean overlapConvexPolygons(Polygon p1, Polygon p2, Intersector.MinimumTranslationVector mtv)
p1
- The first polygon.p2
- The second polygon.mtv
- A Minimum Translation Vector to fill in the case of a collision, or null (optional).public static boolean overlapConvexPolygons(float[] verts1, float[] verts2, Intersector.MinimumTranslationVector mtv)
public static boolean overlapConvexPolygons(float[] verts1, int offset1, int count1, float[] verts2, int offset2, int count2, Intersector.MinimumTranslationVector mtv)
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).public static void splitTriangle(float[] triangle, Plane plane, Intersector.SplitTriangle split)
Intersector.SplitTriangle.front
or Intersector.SplitTriangle.back
will contain the original
triangle, Intersector.SplitTriangle.total
will be one.Intersector.SplitTriangle.front
contains 2 triangles,
Intersector.SplitTriangle.back
contains 1 triangles, Intersector.SplitTriangle.total
will be 3.Intersector.SplitTriangle.front
contains 1 triangle,
Intersector.SplitTriangle.back
contains 2 triangles, Intersector.SplitTriangle.total
will be 3.split
- output SplitTriangleCopyright © 2020. All rights reserved.