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 |
Constructor and Description |
---|
Intersector() |
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 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 |
intersectPolygons(Polygon p1,
Polygon p2,
Polygon overlap)
Intersects two resulting polygons with the same winding 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 |
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,
Vector2 center,
float squareRadius)
Returns whether the given line segment intersects the given circle.
|
static float |
intersectSegmentCircleDisplace(Vector2 start,
Vector2 end,
Vector2 point,
float radius,
Vector2 displacement)
Checks whether the line segment and the circle intersect and returns by how much and in what direction the line has to move
away from the circle to not intersect.
|
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 |
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 counter-clockwise wound vertex arrays overlap.
|
static boolean |
overlapConvexPolygons(Polygon p1,
Polygon p2)
Check whether specified counter-clockwise wound convex polygons overlap.
|
static boolean |
overlapConvexPolygons(Polygon p1,
Polygon p2,
Intersector.MinimumTranslationVector mtv)
Check whether specified counter-clockwise wound convex polygons overlap.
|
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)
point
- the pointt1
- 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 arraypoint
- The pointpublic 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 (optional)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 float intersectSegmentCircleDisplace(Vector2 start, Vector2 end, Vector2 point, float radius, Vector2 displacement)
start
- The line segment starting pointend
- The line segment end pointpoint
- The center of the circleradius
- The radius of the circledisplacement
- The displacement vector set by the method having unit lengthpublic 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.ray
- The rayplane
- The planeintersection
- 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)
x
- y
- z
- x2
- y2
- z2
- plane
- public static boolean intersectRayTriangle(Ray ray, Vector3 t1, Vector3 t2, Vector3 t3, Vector3 intersection)
Ray
and a triangle, returning the intersection point in intersection.ray
- The rayt1
- 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.
ray
- The raybox
- The boxintersection
- The intersection point (optional)public static boolean intersectRayBoundsFast(Ray ray, BoundingBox box)
Ray
and BoundingBox
intersect.ray
- The raybox
- The bounding boxpublic static boolean intersectRayBoundsFast(Ray ray, Vector3 center, Vector3 dimensions)
Ray
and BoundingBox
intersect.ray
- The raycenter
- The center of the bounding boxdimensions
- The dimensions (width, height and depth) of the bounding boxpublic static boolean intersectRayTriangles(Ray ray, float[] triangles, Vector3 intersection)
ray
- The raytriangles
- The triangles, each successive 3 elements from a vertexintersection
- The nearest intersection point (optional)public static boolean intersectRayTriangles(Ray ray, float[] vertices, short[] indices, int vertexSize, Vector3 intersection)
ray
- The rayvertices
- the verticesindices
- 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)
ray
- The raytriangles
- The trianglesintersection
- The nearest intersection point (optional)public 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 linepolygon
- The polygonpublic static boolean intersectRectangles(Rectangle rectangle1, Rectangle rectangle2, Rectangle intersection)
intersection
rectangle to the
area of overlap.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.verts2
- Vertices of the second polygon.mtv
- 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.triangle
- plane
- split
- output SplitTriangleCopyright © 2017. All rights reserved.