Module org.dyn4j

• Object
• All Implemented Interfaces:
TimeOfImpactDetector

extends Object
implements TimeOfImpactDetector
Implements the Conservative Advancement technique to solve for the time of impact.

This method assumes that translation and rotation are linear and computes the time of impact within a given tolerance.

This method is described in "Continuous Collision Detection and Physics" by Erwin Coumans (Draft).

Since:
1.2.0
Version:
3.1.5
Author:
William Bittle
• ### Field Detail

• #### DEFAULT_DISTANCE_EPSILON

public static final double DEFAULT_DISTANCE_EPSILON
The default distance epsilon
• #### DEFAULT_MAX_ITERATIONS

public static final int DEFAULT_MAX_ITERATIONS
The default maximum number of iterations
Constant Field Values
• ### Constructor Detail

Default constructor.

Uses Gjk as the DistanceDetector.

Optional constructor.
Parameters:
distanceDetector - the distance detector
Throws:
NullPointerException - if distanceDetector is null
• ### Method Detail

• #### getTimeOfImpact

public boolean getTimeOfImpact​(Convex convex1,
Transform transform1,
Vector2 dp1,
double da1,
Convex convex2,
Transform transform2,
Vector2 dp2,
double da2,
TimeOfImpact toi)
Description copied from interface: TimeOfImpactDetector
Detects whether the given Convex Shapes collide given their current positions and orientation and the rate of change their position and orientation, returning the time of impact within an epsilon.

If a collision is detected, the toi parameter will be filled with the time of impact and the separation at the time of impact.

If a time of impact is detected, the time will be in the range [0, 1]. This can be used, along with the change and position and orientation, to place to the shapes at the time of impact. Note that the shapes will still be separated, by a small amount, at the time of impact.

This method returns false if the shape do not collide.

Specified by:
getTimeOfImpact in interface TimeOfImpactDetector
Parameters:
convex1 - the first convex shape
transform1 - the first convex shape's transform
dp1 - the change in position of the first shape
da1 - the change in orientation of the first shape
convex2 - the second convex shape
transform2 - the second convex shape's transform
dp2 - the change in position of the second shape
da2 - the change in orientation of the second shape
toi - the TimeOfImpact object to be filled in the case of a collision
Returns:
boolean true if a collision was detected
• #### getTimeOfImpact

public boolean getTimeOfImpact​(Convex convex1,
Transform transform1,
Vector2 dp1,
double da1,
Convex convex2,
Transform transform2,
Vector2 dp2,
double da2,
double t1,
double t2,
TimeOfImpact toi)
Description copied from interface: TimeOfImpactDetector
Detects whether the given Convex Shapes collide given their current positions and orientation and the rate of change their position and orientation in the time range of [t1, t2] and returning the time of impact within an epsilon.

If a collision is detected, the toi parameter will be filled with the time of impact and the separation at the time of impact.

If a time of impact is detected, the time will be in the range [0, 1]. This can be used, along with the change and position and orientation, to place to the shapes at the time of impact. Note that the shapes will still be separated, by a small amount, at the time of impact.

This method returns false if the shape do not collide.

Specified by:
getTimeOfImpact in interface TimeOfImpactDetector
Parameters:
convex1 - the first convex shape
transform1 - the first convex shape's transform
dp1 - the change in position of the first shape
da1 - the change in orientation of the first shape
convex2 - the second convex shape
transform2 - the second convex shape's transform
dp2 - the change in position of the second shape
da2 - the change in orientation of the second shape
t1 - the lower time bound
t2 - the upper time bound
toi - the TimeOfImpact object to be filled in the case of a collision
Returns:
boolean true if a collision was detected
• #### setDistanceDetector

public void setDistanceDetector​(DistanceDetector distanceDetector)
Sets the DistanceDetector to be used.
Parameters:
distanceDetector - the distance detector
Throws:
NullPointerException - if distanceDetector is null
• #### getDistanceEpsilon

public double getDistanceEpsilon()
Returns the distance epsilon used to determine when a sufficient solution has been found.
Returns:
double the distance epsilon
• #### setDistanceEpsilon

public void setDistanceEpsilon​(double distanceEpsilon)
Sets the distance epsilon used to determine when a sufficient solution has been found.
Parameters:
distanceEpsilon - the distance epsilon; must be greater than zero
Throws:
IllegalArgumentException - if distanceEpsilon is less than or equal to zero
• #### getMaxIterations

public int getMaxIterations()
Returns the maximum number of iterations that will be performed by the root finder.
Returns:
the maximum number of iterations the root finder will perform
• #### setMaxIterations

public void setMaxIterations​(int maxIterations)
Sets the maximum number of iterations that will be performed by the root finder.

Lower values increase performance yet decrease accuracy whereas higher values decrease performance and increase accuracy.

Parameters:
maxIterations - the maximum number of iterations in the range [5, ∞]
Throws:
IllegalArgumentException - if maxIterations is less than 5