Commit 433de40e authored by ronan's avatar ronan
Browse files

Add optimised circle detection

parent 3a038543
Pipeline #2252 passed with stage
in 59 seconds
package org.cora.maths.collision;
import org.cora.maths.FloatA;
import org.cora.maths.Form;
import org.cora.maths.Matrix2;
import org.cora.maths.Vector2D;
import org.cora.maths.*;
import java.util.ArrayList;
/**
* Tools to detect collision between two convex polygons
* Tools to detect collision between two convex polygons and taking account of velocity
*/
public class CollisionDetector
{
/**
*
* Detect collision
* @param A test form A
* @param B test form B
* @param VA velocity of object A
......@@ -28,6 +25,24 @@ public class CollisionDetector
return collisionSat(A, B, VA, VB, push, t);
}
/**
* Detect collision with circle optimisiation detection
* @param A test form A
* @param B test form B
* @param cA circle containing A
* @param cB circle containing B
* @param VA velocity of object A
* @param VB velocity of object B
* @param push a blank vector to store the penetration vector
* @param t a blank float to store the result of amount of penetration
* @return result of collision detection testing
*/
public static boolean isCollidingOptimised(Form A, Form B, Circle cA, Circle cB, Vector2D VA, Vector2D VB,
Vector2D push, FloatA t)
{
return collisionSat(cA, cB, VA, VB, push, t) && collisionSat(A, B, VA, VB, push, t);
}
private static boolean collisionSat(Form A, Form B, Vector2D VA,
Vector2D VB, Vector2D push, FloatA t)
{
......
package org.cora.maths.collision;
import org.cora.maths.Circle;
import org.cora.maths.Form;
import org.cora.maths.Matrix2;
import org.cora.maths.Vector2D;
......@@ -9,13 +10,31 @@ import java.util.ArrayList;
public class CollisionDetectorNoT
{
// Collisions detection
/**
* Detect collision
* @param A test form A
* @param B test form B
* @return result of collision detection testing
*/
public static boolean isColliding(Form A, Form B)
{
return collisionSatFree(A, B);
return collisionSat(A, B);
}
/**
* Detect collision with circle optimisiation detection
* @param A test form A
* @param B test form B
* @param cA circle containing A
* @param cB circle containing B
* @return result of collision detection testing
*/
public static boolean isCollidingOptimised(Form A, Form B, Circle cA, Circle cB)
{
return collisionSat(cA, cB) && collisionSat(A, B);
}
private static boolean collisionSatFree(Form A, Form B)
private static boolean collisionSat(Form A, Form B)
{
// Les vecteurs VA et VB sont exprimés dans le repère world
// Les points PA et PB sont exprimés dans le repères world
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment