java.lang.Object
com.marginallyclever.convenience.helpers.IntersectionHelper

public abstract class IntersectionHelper extends Object
Convenience methods for detecting intersection of various mesh.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static javax.vecmath.Vector3d
    buildNormalFrom3Points(javax.vecmath.Vector3d v0, javax.vecmath.Vector3d v1, javax.vecmath.Vector3d v2)
     
    static javax.vecmath.Vector3d
    centerOfCircumscribedCircle(javax.vecmath.Vector3d a, javax.vecmath.Vector3d b, javax.vecmath.Vector3d c)
    static javax.vecmath.Vector3d
    centerOfCircumscribedSphere(javax.vecmath.Vector3d a, javax.vecmath.Vector3d b, javax.vecmath.Vector3d c, double r)
    find the center of the sphere formed by the three points p and the radius.
    static double
    CPADistance(javax.vecmath.Vector3d a0, javax.vecmath.Vector3d b0, javax.vecmath.Vector3d a1, javax.vecmath.Vector3d b1)
    find the closest point of approach between two lines
    static boolean
    separation of axes theorem used to find intersection of two arbitrary boxes.
    static boolean
    test intersection of two cylinders.
    static boolean
    meshMesh(javax.vecmath.Matrix4d ma, Mesh sa, javax.vecmath.Matrix4d mb, Mesh sb)
     
    static double
    rayBox(Ray ray, javax.vecmath.Point3d boxMin, javax.vecmath.Point3d boxMax)
    find distance to box, if hit.
    static double
    rayPlane(Ray ray, Plane translationPlane)
    Returns the distance to the plane, or Double.MAX_VALUE if there is no intersection.
    static double
    raySphere(Ray ray, javax.vecmath.Point3d center, double radius)
    ray/sphere intersection.
    static double
    rayTriangle(Ray ray, javax.vecmath.Vector3d v0, javax.vecmath.Vector3d v1, javax.vecmath.Vector3d v2)
    The implementation uses the Möller–Trumbore intersection algorithm to compute the intersection between a ray and a triangle.
    static boolean
    sphereBox(javax.vecmath.Tuple3d point, double r2, javax.vecmath.Tuple3d max, javax.vecmath.Tuple3d min)
    is point within r of box (max,min)?

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • IntersectionHelper

      public IntersectionHelper()
  • Method Details

    • cylinderCylinder

      public static boolean cylinderCylinder(Cylinder cA, Cylinder cB)
      test intersection of two cylinders. From ...
      Parameters:
      cA - cylinder A
      cB - cylinder B
      Returns:
      true if intersect
    • CPADistance

      public static double CPADistance(javax.vecmath.Vector3d a0, javax.vecmath.Vector3d b0, javax.vecmath.Vector3d a1, javax.vecmath.Vector3d b1)
      find the closest point of approach between two lines
      Parameters:
      a0 - line 1 start
      b0 - line 2 start
      a1 - line 1 end
      b1 - line 2 end
      Returns:
      distance between the two lines at the closest point of approach.
    • cuboidCuboid

      public static boolean cuboidCuboid(AABB a, AABB b)
      separation of axes theorem used to find intersection of two arbitrary boxes.
      Parameters:
      a - first cuboid
      b - second cuboid
      Returns:
      true if cuboids intersect
    • meshMesh

      public static boolean meshMesh(javax.vecmath.Matrix4d ma, Mesh sa, javax.vecmath.Matrix4d mb, Mesh sb)
      Returns:
      true if the two mesh intersect.
    • raySphere

      public static double raySphere(Ray ray, javax.vecmath.Point3d center, double radius)
      ray/sphere intersection. see reference.
      Parameters:
      ray - start and direction
      center - center of sphere
      radius - radius of sphere
      Returns:
      distance to first hit. negative values for no hit/behind start.
    • rayBox

      public static double rayBox(Ray ray, javax.vecmath.Point3d boxMin, javax.vecmath.Point3d boxMax)
      find distance to box, if hit. See scratchapixel
      Parameters:
      ray - start and direction
      boxMin - lower bounds
      boxMax - upper bounds
      Returns:
      >=0 for hit, negative numbers for hits behind the ray origin or no hit.
    • centerOfCircumscribedCircle

      public static javax.vecmath.Vector3d centerOfCircumscribedCircle(javax.vecmath.Vector3d a, javax.vecmath.Vector3d b, javax.vecmath.Vector3d c)
      Parameters:
      a - point 1
      b - point 2
      c - point 3
      Returns:
      the center of the circumscribed circle.
    • centerOfCircumscribedSphere

      public static javax.vecmath.Vector3d centerOfCircumscribedSphere(javax.vecmath.Vector3d a, javax.vecmath.Vector3d b, javax.vecmath.Vector3d c, double r)
      find the center of the sphere formed by the three points p and the radius. see Stack overflow
      Parameters:
      a - point
      b - point
      c - point
      r - radius
      Returns:
      the center of the sphere formed by the three points p and the radius.
    • rayTriangle

      public static double rayTriangle(Ray ray, javax.vecmath.Vector3d v0, javax.vecmath.Vector3d v1, javax.vecmath.Vector3d v2)
      The implementation uses the Möller–Trumbore intersection algorithm to compute the intersection between a ray and a triangle. The algorithm works by computing the intersection point between the ray and the plane defined by the triangle, and then checking if the intersection point is inside the triangle.
      Note that this implementation assumes that the triangle is defined in a counter-clockwise winding order when viewed from the outside. If the triangle is defined in clockwise order, the direction of one of the cross products needs to be reversed to get the correct intersection result. See also Wikipedia.
      Parameters:
      ray - origin and direction
      v0 - point 1
      v1 - point 2
      v2 - point 3
      Returns:
      distance to the intersection, negative numbers for hits behind camera, Double.MAX_VALUE for no hit.
    • rayPlane

      public static double rayPlane(Ray ray, Plane translationPlane)
      Returns the distance to the plane, or Double.MAX_VALUE if there is no intersection.
      Parameters:
      ray - origin and direction
      translationPlane - plane
      Returns:
      the distance to the plane, or Double.MAX_VALUE if there is no intersection.
    • buildNormalFrom3Points

      public static javax.vecmath.Vector3d buildNormalFrom3Points(javax.vecmath.Vector3d v0, javax.vecmath.Vector3d v1, javax.vecmath.Vector3d v2)
    • sphereBox

      public static boolean sphereBox(javax.vecmath.Tuple3d point, double r2, javax.vecmath.Tuple3d max, javax.vecmath.Tuple3d min)
      is point within r of box (max,min)?
      Parameters:
      point - the test point
      r2 - the square of the radius
      max - the max point of the box
      min - the min point of the box
      Returns:
      true if point is within r of box (max,min)