A Monogame implementation of the Separating Axis Theorem for convex polygon intersection.
View on nuget or install directly with:
dotnet add package Halfcut.SeparatingAxisTheorem.Lib --version 0.0.2
using Halfcut.SeparatingAxisTheorem.Lib;
class Game {
private Polygon _polygon1;
private Polygon _polygon2;
public Game() {
_polygon1 = PolygonFactory.CreateRectangle(x1, y1, w1, h2);
_polygon2 = PolygonFactory.CreateRectangle(x2, y2, w2, h2);
}
public void Update(float dt) {
var isIntersecting = _polygon1.IntersectsWith(_polygon2);
}
}
Run the demo code with:
git clone [email protected]:tedigc/SeparatingAxisTheorem.git
cd SeparatingAxisTheorem
dotnet build
dotnet run --project SeparatingAxisTheorem.Demo/SeparatingAxisTheorem.Demo.csproj
You can move the rotating square with WASD.
- Circle collision
- Improve api for translating and rotating polygons
- Publish as a nuget package
- Calculate the minimum translation vector (MTV)
- Convex decomposition for non-convex polygons
- Exception handling
Created by Ted Cater (tedigc)