- Description
- Field Summary
- Constructor Summary
- Method Summary
- Field Details
- Constructor Details
- Method Details
- intersectVectorAABB(Vector3d, Vector3d, double, double, double, Box, Vector2d)
- intersectRayAABB(Vector3d, Vector3d, double, double, double, Box, Vector2d)
- intersectRayAABB(Vector3d, Vector3d, double, double, double, Box)
- intersectVectorAABB(Vector3d, Vector3d, double, double, double, double, double, Vector2d)
- intersectRayAABB(Vector3d, Vector3d, double, double, double, double, double, Vector2d)
- intersectSweptAABBs(Vector3d, Vector3d, Box, Vector3d, Box, Vector2d, Box)
- intersectSweptAABBs(Vector3d, Vector3d, Box, double, double, double, Box, Vector2d, Box)
- intersect1D(double, double, double, double, Vector2d)
- isDisjoint(int)
- isOverlapping(int)
- isTouching(int)
- intersectAABBs(Vector3d, Box, Vector3d, Box)
- intersectAABBs(double, double, double, Box, double, double, double, Box)
- intersect1D(double, double, double, double, double, double)
- intersectAABBs(double, double, double, Box, double, double, double, Box, double)
- intersect1D(double, double, double, double, double, double, double)
Class CollisionMath
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intResult code for intersection of two boxes neither touching nor overlappingstatic final ThreadLocal<org.joml.Vector2d> static final intCombination of all box intersection result OVERLAP_ flagsstatic final intMask of all box intersection result OVERLAP_ flagsstatic final intResult flag for intersection of two boxes overlapping in x directionstatic final intResult flag for intersection of two boxes overlapping in y directionstatic final intResult flag for intersection of two boxes overlapping in z directionstatic final intMask/combination of all box intersection result TOUCH_ flagsstatic final intResult flag for intersection of two boxes touching in x directionstatic final intResult flag for intersection of two boxes touching in y directionstatic final intResult flag for intersection of two boxes touching in z direction -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic intintersect1D(double p, double pMin, double pMax, double q, double qMin, double qMax) 1D helper class for Rect/AABB intersection computation.static intintersect1D(double p, double pMin, double pMax, double q, double qMin, double qMax, double thickness) 1D helper class for Rect/AABB intersection computation with thickness parameters.static booleanintersect1D(double p, double s, double min, double max, org.joml.Vector2d minMax) Helper routine for AABB ray cast.static intintersectAABBs(double px, double py, double pz, Box bbP, double qx, double qy, double qz, Box bbQ) Test if two AABBs intersect or touchstatic intintersectAABBs(double px, double py, double pz, Box bbP, double qx, double qy, double qz, Box bbQ, double thickness) Test if two AABBs intersect or touch with thickness parameter.static intintersectAABBs(org.joml.Vector3d p, Box bbP, org.joml.Vector3d q, Box bbQ) Test if two AABBs intersect or touchstatic booleanintersectRayAABB(org.joml.Vector3d pos, org.joml.Vector3d ray, double x, double y, double z, double radius, double height, org.joml.Vector2d minMax) Find intersection between (infinite) ray starting at pos with given length and AABBstatic doubleintersectRayAABB(org.joml.Vector3d pos, org.joml.Vector3d ray, double x, double y, double z, Box box) Find intersection between (infinite) ray starting at pos with given length and AABBstatic booleanintersectRayAABB(org.joml.Vector3d pos, org.joml.Vector3d ray, double x, double y, double z, Box box, org.joml.Vector2d minMax) Find intersection between (infinite) ray starting at pos with given length and AABBstatic booleanintersectSweptAABBs(org.joml.Vector3d posP, org.joml.Vector3d vP, Box p, double qx, double qy, double qz, Box q, org.joml.Vector2d minMax, Box temp) Find collision between an AABB swept along a ray with another AABBstatic booleanintersectSweptAABBs(org.joml.Vector3d posP, org.joml.Vector3d vP, Box p, org.joml.Vector3d posQ, Box q, org.joml.Vector2d minMax, Box temp) Find collision between an AABB swept along a ray with another AABBstatic booleanintersectVectorAABB(org.joml.Vector3d pos, org.joml.Vector3d vec, double x, double y, double z, double radius, double height, org.joml.Vector2d minMax) Find intersection between vector starting at pos and AABBstatic booleanintersectVectorAABB(org.joml.Vector3d pos, org.joml.Vector3d vec, double x, double y, double z, Box box, org.joml.Vector2d minMax) Find intersection between vector starting at pos and AABBstatic booleanisDisjoint(int code) Test intersection code for disjoint boxes.static booleanisOverlapping(int code) Test intersection code for overlapping boxes.static booleanisTouching(int code) Test intersection code for touching boxes.
-
Field Details
-
MIN_MAX
-
DISJOINT
public static final int DISJOINTResult code for intersection of two boxes neither touching nor overlapping- See Also:
-
TOUCH_X
public static final int TOUCH_XResult flag for intersection of two boxes touching in x direction- See Also:
-
TOUCH_Y
public static final int TOUCH_YResult flag for intersection of two boxes touching in y direction- See Also:
-
TOUCH_Z
public static final int TOUCH_ZResult flag for intersection of two boxes touching in z direction- See Also:
-
TOUCH_ANY
public static final int TOUCH_ANYMask/combination of all box intersection result TOUCH_ flags- See Also:
-
OVERLAP_X
public static final int OVERLAP_XResult flag for intersection of two boxes overlapping in x direction- See Also:
-
OVERLAP_Y
public static final int OVERLAP_YResult flag for intersection of two boxes overlapping in y direction- See Also:
-
OVERLAP_Z
public static final int OVERLAP_ZResult flag for intersection of two boxes overlapping in z direction- See Also:
-
OVERLAP_ANY
public static final int OVERLAP_ANYMask of all box intersection result OVERLAP_ flags- See Also:
-
OVERLAP_ALL
public static final int OVERLAP_ALLCombination of all box intersection result OVERLAP_ flags- See Also:
-
-
Constructor Details
-
CollisionMath
public CollisionMath()
-
-
Method Details
-
intersectVectorAABB
public static boolean intersectVectorAABB(@Nonnull org.joml.Vector3d pos, @Nonnull org.joml.Vector3d vec, double x, double y, double z, @Nonnull Box box, @Nonnull org.joml.Vector2d minMax) Find intersection between vector starting at pos and AABB- Parameters:
pos- start point of vectorvec- direction of vectorx- footpoint of AABBy- footpoint of AABBz- footpoint of AABBbox- AABBminMax- result values for collision point- Returns:
- true if collision. minMax.x will then hold nearest collision vector scale, minMax.y farthest collision scale.
-
intersectRayAABB
public static boolean intersectRayAABB(@Nonnull org.joml.Vector3d pos, @Nonnull org.joml.Vector3d ray, double x, double y, double z, @Nonnull Box box, @Nonnull org.joml.Vector2d minMax) Find intersection between (infinite) ray starting at pos with given length and AABB- Parameters:
pos- start point of vectorray- direction with length of rayx- footpoint of AABBy- footpoint of AABBz- footpoint of AABBbox- AABBminMax- result values for collision point- Returns:
- true if collision. minMax.x will then hold nearest collision vector scale, minMax.y farthest collision scale.
-
intersectRayAABB
public static double intersectRayAABB(@Nonnull org.joml.Vector3d pos, @Nonnull org.joml.Vector3d ray, double x, double y, double z, @Nonnull Box box) Find intersection between (infinite) ray starting at pos with given length and AABBVariant uses a thread local minMax value instead of passing it as argument if only the minimum value is required.
- Parameters:
pos- start point of vectorray- direction with length of rayx- footpoint of AABBy- footpoint of AABBz- footpoint of AABBbox- AABB- Returns:
- Return nearest distance of ray intersection or
-Double.MAX_VALUE
-
intersectVectorAABB
public static boolean intersectVectorAABB(@Nonnull org.joml.Vector3d pos, @Nonnull org.joml.Vector3d vec, double x, double y, double z, double radius, double height, @Nonnull org.joml.Vector2d minMax) Find intersection between vector starting at pos and AABB- Parameters:
pos- start point of vectorvec- direction of vectorx- footpoint of AABBy- footpoint of AABBz- footpoint of AABBradius- radius of AABBheight- height of AABBminMax- result values for collision point- Returns:
- true if collision. minMax.x will then hold nearest collision vector scale, minMax.y farthest collision scale.
-
intersectRayAABB
public static boolean intersectRayAABB(@Nonnull org.joml.Vector3d pos, @Nonnull org.joml.Vector3d ray, double x, double y, double z, double radius, double height, @Nonnull org.joml.Vector2d minMax) Find intersection between (infinite) ray starting at pos with given length and AABB- Parameters:
pos- start point of vectorray- direction with length of rayx- footpoint of AABBy- footpoint of AABBz- footpoint of AABBradius- radius of AABBheight- height of AABBminMax- result values for collision point- Returns:
- true if collision. minMax.x will then hold nearest collision vector scale, minMax.y farthest collision scale.
-
intersectSweptAABBs
public static boolean intersectSweptAABBs(@Nonnull org.joml.Vector3d posP, @Nonnull org.joml.Vector3d vP, @Nonnull Box p, @Nonnull org.joml.Vector3d posQ, @Nonnull Box q, @Nonnull org.joml.Vector2d minMax, @Nonnull Box temp) Find collision between an AABB swept along a ray with another AABB- Parameters:
posP- initial position of swept AABBvP- sweep directionp- swept boxposQ- position of other AABBq- other AABBminMax- result values for collision pointtemp- box used for temporary computations- Returns:
- true if collision. minMax.x will then hold nearest collision vector scale, minMax.y farthest collision scale.
-
intersectSweptAABBs
public static boolean intersectSweptAABBs(@Nonnull org.joml.Vector3d posP, @Nonnull org.joml.Vector3d vP, @Nonnull Box p, double qx, double qy, double qz, @Nonnull Box q, @Nonnull org.joml.Vector2d minMax, @Nonnull Box temp) Find collision between an AABB swept along a ray with another AABB- Parameters:
posP- initial position of swept AABBvP- sweep directionp- swept boxqx- position of other AABBqy- position of other AABBqz- position of other AABBq- other AABBminMax- result values for collision pointtemp- box used for temporary computations- Returns:
- true if collision. minMax.x will then hold nearest collision vector scale, minMax.y farthest collision scale.
-
intersect1D
public static boolean intersect1D(double p, double s, double min, double max, @Nonnull org.joml.Vector2d minMax) Helper routine for AABB ray cast. Test for each dimension.The minMax value must be initialized with { 0, Double.MaxValue } before first test. *
- Parameters:
p- ray positions- ray lengthmin- min box coordinatemax- max box coordinateminMax- resulting collision distance x for minimum, y for maximum- Returns:
- true if intersection possible
-
isDisjoint
public static boolean isDisjoint(int code) Test intersection code for disjoint boxes.- Parameters:
code- Intersection code- Returns:
- true if boxes are disjoint, false if overlap or touching
-
isOverlapping
public static boolean isOverlapping(int code) Test intersection code for overlapping boxes.- Parameters:
code- Intersection code- Returns:
- true if boxes are overlapping, false if boxes are touching or disjoint
-
isTouching
public static boolean isTouching(int code) Test intersection code for touching boxes.- Parameters:
code- Intersection code- Returns:
- true if boxes are touching, false if boxes are overlapping or disjoint
-
intersectAABBs
public static int intersectAABBs(@Nonnull org.joml.Vector3d p, @Nonnull Box bbP, @Nonnull org.joml.Vector3d q, @Nonnull Box bbQ) Test if two AABBs intersect or touchIntervals are assumed to touch when the distance between them is less than MOVEMENT_THRESHOLD to compensate for computational inaccuracies.
- Parameters:
p- origin of boxbbP- boxq- origin of other boxbbQ- other box- Returns:
- Either DISJOINT or combination or TOUCH_ and OVERLAP_ bits (intersection code)
-
intersectAABBs
public static int intersectAABBs(double px, double py, double pz, @Nonnull Box bbP, double qx, double qy, double qz, @Nonnull Box bbQ) Test if two AABBs intersect or touchIntervals are assumed to touch when the distance between them is less than MOVEMENT_THRESHOLD to compensate for computational inaccuracies.
- Parameters:
px- origin of boxpy- origin of boxpz- origin of boxbbP- boxqx- origin of other boxqy- origin of other boxqz- origin of other boxbbQ- other box- Returns:
- Either DISJOINT or combination or TOUCH_ and OVERLAP_ bits (intersection code)
-
intersect1D
public static int intersect1D(double p, double pMin, double pMax, double q, double qMin, double qMax) 1D helper class for Rect/AABB intersection computation.Intervals are assumed to touch when the distance between them is less than MOVEMENT_THRESHOLD to compensate for computational inaccuracies.
- Parameters:
p- interval positionpMin- interval extentpMax- interval extentq- other interval positionqMin- other interval extentqMax- other interval extent- Returns:
- OVERLAP_ANY when intervals overlap, TOUCH_ANY when intervals sit (closely) side by side, else DISJOINT
-
intersectAABBs
public static int intersectAABBs(double px, double py, double pz, @Nonnull Box bbP, double qx, double qy, double qz, @Nonnull Box bbQ, double thickness) Test if two AABBs intersect or touch with thickness parameter.Intervals are assumed to touch when the distance between them is less than
thicknessto compensate for computational inaccuracies.- Parameters:
px- origin of boxpy- origin of boxpz- origin of boxbbP- boxqx- origin of other boxqy- origin of other boxqz- origin of other boxbbQ- other boxthickness- overlap distance which is still considered as touching- Returns:
- Either DISJOINT or combination or TOUCH_ and OVERLAP_ bits (intersection code)
-
intersect1D
public static int intersect1D(double p, double pMin, double pMax, double q, double qMin, double qMax, double thickness) 1D helper class for Rect/AABB intersection computation with thickness parameters.Intervals are assumed to touch when the distance between them is less than
thicknessto compensate for computational inaccuracies.- Parameters:
p- interval positionpMin- interval extentpMax- interval extentq- other interval positionqMin- other interval extentqMax- other interval extentthickness- overlap distance which is still considered as touching- Returns:
- OVERLAP_ANY when intervals overlap, TOUCH_ANY when intervals sit (closely) side by side, else DISJOINT
-