Package arc.math.geom

Class Intersector3D

java.lang.Object
arc.math.geom.Intersector3D

public class Intersector3D extends Object
  • Constructor Details

    • Intersector3D

      public Intersector3D()
  • Method Details

    • intersectRayPlane

      public static boolean intersectRayPlane(Ray ray, Plane plane, Vec3 intersection)
      Intersects a Ray and a Plane. The intersection point is stored in intersection in case an intersection is present.
      Parameters:
      ray - The ray
      plane - The plane
      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, 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

      public static boolean intersectRayTriangle(Ray ray, Vec3 t1, Vec3 t2, Vec3 t3, Vec3 intersection)
      Intersect a Ray and a triangle, returning the intersection point in intersection.
      Parameters:
      ray - The ray
      t1 - The first vertex of the triangle
      t2 - The second vertex of the triangle
      t3 - The third vertex of the triangle
      intersection - The intersection point (optional)
      Returns:
      True in case an intersection is present.
    • intersectRaySphere

      public static boolean intersectRaySphere(Ray ray, Vec3 center, float radius, Vec3 intersection)
      Intersects a Ray and a sphere, returning the intersection point in intersection.
      Parameters:
      ray - The ray, the direction component must be normalized before calling this method
      center - The center of the sphere
      radius - The radius of the sphere
      intersection - The intersection point (optional, can be null)
      Returns:
      Whether an intersection is present.
    • intersectRayBounds

      public static boolean intersectRayBounds(Ray ray, BoundingBox box, Vec3 intersection)
      Intersects a 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.

      Parameters:
      ray - The ray
      box - The box
      intersection - The intersection point (optional)
      Returns:
      Whether an intersection is present.
    • intersectRayBoundsFast

      public static boolean intersectRayBoundsFast(Ray ray, BoundingBox box)
      Quick check whether the given Ray and BoundingBox intersect.
      Parameters:
      ray - The ray
      box - The bounding box
      Returns:
      Whether the ray and the bounding box intersect.
    • intersectRayBoundsFast

      public static boolean intersectRayBoundsFast(Ray ray, Vec3 center, Vec3 dimensions)
      Quick check whether the given Ray and BoundingBox intersect.
      Parameters:
      ray - The ray
      center - The center of the bounding box
      dimensions - The dimensions (width, height and depth) of the bounding box
      Returns:
      Whether the ray and the bounding box intersect.
    • intersectSegmentPlane

      public static boolean intersectSegmentPlane(Vec3 start, Vec3 end, Plane plane, Vec3 intersection)
    • intersectRayTriangles

      public static boolean intersectRayTriangles(Ray ray, float[] triangles, Vec3 intersection)
      Intersects the given ray with list of triangles. Returns the nearest intersection point in intersection
      Parameters:
      ray - The ray
      triangles - The triangles, each successive 3 elements from a vertex
      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, Vec3 intersection)
      Intersects the given ray with list of triangles. Returns the nearest intersection point in intersection
      Parameters:
      ray - The ray
      vertices - the vertices
      indices - the indices, each successive 3 shorts index the 3 vertices of a triangle
      vertexSize - the size of a vertex in floats
      intersection - The nearest intersection point (optional)
      Returns:
      Whether the ray and the triangles intersect.
    • intersectRayTriangles

      public static boolean intersectRayTriangles(Ray ray, Seq<Vec3> triangles, Vec3 intersection)
      Intersects the given ray with list of triangles. Returns the nearest intersection point in intersection
      Parameters:
      ray - The ray
      triangles - The triangles
      intersection - The nearest intersection point (optional)
      Returns:
      Whether the ray and the triangles intersect.
    • splitTriangle

      public static void splitTriangle(float[] triangle, Plane plane, Intersector3D.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:

      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