Class IntersectionHelper
java.lang.Object
com.marginallyclever.convenience.helpers.IntersectionHelper
Convenience methods for detecting intersection of various mesh.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic 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 linesstatic boolean
cuboidCuboid
(AABB a, AABB b) separation of axes theorem used to find intersection of two arbitrary boxes.static boolean
cylinderCylinder
(Cylinder cA, Cylinder cB) test intersection of two cylinders.static boolean
static double
find distance to box, if hit.static double
Returns the distance to the plane, or Double.MAX_VALUE if there is no intersection.static double
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)?
-
Constructor Details
-
IntersectionHelper
public IntersectionHelper()
-
-
Method Details
-
cylinderCylinder
test intersection of two cylinders. From ...- Parameters:
cA
- cylinder AcB
- 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 startb0
- line 2 starta1
- line 1 endb1
- line 2 end- Returns:
- distance between the two lines at the closest point of approach.
-
cuboidCuboid
separation of axes theorem used to find intersection of two arbitrary boxes.- Parameters:
a
- first cuboidb
- 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
ray/sphere intersection. see reference.- Parameters:
ray
- start and directioncenter
- center of sphereradius
- radius of sphere- Returns:
- distance to first hit. negative values for no hit/behind start.
-
rayBox
find distance to box, if hit. See scratchapixel- Parameters:
ray
- start and directionboxMin
- lower boundsboxMax
- 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 1b
- point 2c
- 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
- pointb
- pointc
- pointr
- 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 directionv0
- point 1v1
- point 2v2
- point 3- Returns:
- distance to the intersection, negative numbers for hits behind camera, Double.MAX_VALUE for no hit.
-
rayPlane
Returns the distance to the plane, or Double.MAX_VALUE if there is no intersection.- Parameters:
ray
- origin and directiontranslationPlane
- 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 pointr2
- the square of the radiusmax
- the max point of the boxmin
- the min point of the box- Returns:
- true if point is within r of box (max,min)
-