Package arc.math.geom
Class Intersector3D
java.lang.Object
arc.math.geom.Intersector3D
-
Nested Class Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic float
intersectLinePlane
(float x, float y, float z, float x2, float y2, float z2, Plane plane, Vec3 intersection) Intersects a line and a plane.static boolean
intersectRayBounds
(Ray ray, BoundingBox box, Vec3 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, Vec3 center, Vec3 dimensions) Quick check whether the givenRay
andBoundingBox
intersect.static boolean
intersectRayPlane
(Ray ray, Plane plane, Vec3 intersection) static boolean
intersectRaySphere
(Ray ray, Vec3 center, float radius, Vec3 intersection) Intersects aRay
and a sphere, returning the intersection point in intersection.static boolean
Intersect aRay
and a triangle, returning the intersection point in intersection.static boolean
intersectRayTriangles
(Ray ray, float[] vertices, short[] indices, int vertexSize, Vec3 intersection) Intersects the given ray with list of triangles.static boolean
intersectRayTriangles
(Ray ray, float[] triangles, Vec3 intersection) Intersects the given ray with list of triangles.static boolean
intersectRayTriangles
(Ray ray, Seq<Vec3> triangles, Vec3 intersection) Intersects the given ray with list of triangles.static boolean
intersectSegmentPlane
(Vec3 start, Vec3 end, Plane plane, Vec3 intersection) static void
splitTriangle
(float[] triangle, Plane plane, Intersector3D.SplitTriangle split) Splits the triangle by the plane.
-
Constructor Details
-
Intersector3D
public Intersector3D()
-
-
Method Details
-
intersectRayPlane
Intersects aRay
and aPlane
. The intersection point is stored in intersection in case an intersection is present.- Parameters:
ray
- The rayplane
- The planeintersection
- 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, Vec3 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. -
intersectRayTriangle
Intersect aRay
and a triangle, returning the intersection point in intersection.- Parameters:
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)- Returns:
- True in case an intersection is present.
-
intersectRaySphere
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
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:
ray
- The raybox
- The boxintersection
- The intersection point (optional)- Returns:
- Whether an intersection is present.
-
intersectRayBoundsFast
Quick check whether the givenRay
andBoundingBox
intersect.- Parameters:
ray
- The raybox
- The bounding box- Returns:
- Whether the ray and the bounding box intersect.
-
intersectRayBoundsFast
Quick check whether the givenRay
andBoundingBox
intersect.- Parameters:
ray
- The raycenter
- 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.
-
intersectSegmentPlane
-
intersectRayTriangles
Intersects the given ray with list of triangles. Returns the nearest intersection point in intersection- Parameters:
ray
- The raytriangles
- The triangles, each successive 3 elements from a vertexintersection
- 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, Vec3 intersection) Intersects the given ray with list of triangles. Returns the nearest intersection point in intersection- Parameters:
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)- Returns:
- Whether the ray and the triangles intersect.
-
intersectRayTriangles
Intersects the given ray with list of triangles. Returns the nearest intersection point in intersection- Parameters:
ray
- The raytriangles
- The trianglesintersection
- The nearest intersection point (optional)- Returns:
- Whether the ray and the triangles intersect.
-
splitTriangle
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:
Intersector3D.SplitTriangle.front
orIntersector3D.SplitTriangle.back
will contain the original triangle,Intersector3D.SplitTriangle.total
will be one. - Triangle has two vertices in front, one behind:
Intersector3D.SplitTriangle.front
contains 2 triangles,Intersector3D.SplitTriangle.back
contains 1 triangles,Intersector3D.SplitTriangle.total
will be 3. - Triangle has one vertex in front, two behind:
Intersector3D.SplitTriangle.front
contains 1 triangle,Intersector3D.SplitTriangle.back
contains 2 triangles,Intersector3D.SplitTriangle.total
will be 3.
The input triangle should have the form: x, y, z, x2, y2, z2, x3, y3, z3. One can add additional attributes per vertex which will be interpolated if split, such as texture coordinates or normals. Note that these additional attributes won't be normalized, as might be necessary in case of normals.
- Parameters:
split
- output SplitTriangle
- Triangle is fully in front/behind:
-