Skip to content

Latest commit

 

History

History
55 lines (38 loc) · 1.27 KB

README.md

File metadata and controls

55 lines (38 loc) · 1.27 KB

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

  • 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)