SeparatingAxisTheorem
A MonoGame implementation of the Separating Axis Theorem (SAT) for convex polygon intersection.
Install / Use
/learn @tedigc/SeparatingAxisTheoremREADME
SeparatingAxisTheorem
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
Usage
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);
}
}
Demo
Run the demo code with:
git clone git@github.com:tedigc/SeparatingAxisTheorem.git
cd SeparatingAxisTheorem
dotnet build
dotnet run --project SeparatingAxisTheorem.Demo/SeparatingAxisTheorem.Demo.csproj
You can move the rotating square with WASD.
Extensions
- [x] Circle collision
- [x] Improve api for translating and rotating polygons
- [x] Publish as a nuget package
- [ ] Calculate the minimum translation vector (MTV)
- [ ] Convex decomposition for non-convex polygons
- [ ] Exception handling
Created by Ted Cater (tedigc)
