#collision #2d #geometry #gjk

lgeo

2D Geometry library, focusing on collision computation

8 stable releases

1.0.7 Apr 11, 2022
1.0.6 Apr 9, 2022
1.0.3 Apr 8, 2022
1.0.2 Apr 6, 2022

#1754 in Algorithms

34 downloads per month

MIT license

17KB
398 lines

L-Geo

Documentation Version License

2D Geometry library, written in Rust and based on lmaths.

Provides classic 2D shapes, such as :

  • Circles
  • Rectangles
  • Convex Polygons

It implements the GJK algorithm to compute collision and EPA (yet to be developped) to extrude collision informations.

Examples :

First, always create a GJK struct, which hold your settings, like the contact tolerance :

let gjk = GJK::new();

Then you can start spawning shapes :

let c = Circle::new(Vector2::new(4.6, -3.2), 1.43);
let r = AABB::new(Vector2::new(-1.0, 0.5), Vector2::new(2.0, 1.0));
let p = Polygon::new(Vector2::new(0.0, 0.0),
                    vec![Vector2::new(0.0, 0.5),
                         Vector2::new(-1.5, -0.5),
                         Vector2::new(-3.0, 0.5),
                    ]);

Finally, you can check for collisions between them. Converting the result to a boolean is done by calling result.is_some(), as the intersect() function return the final Simplex of GJK.

let c_vs_r = gjk.intersect(&c, &r).is_some(); // False
let c_vs_p = gjk.intersect(&c, &p).is_some(); // False
let r_vs_p = gjk.intersect(&r, &p).is_some(); // True

Dependencies

~90KB