Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/winstxnhdw/2d-separating-axis-theorem
C++ implementation of a 2D separating axis algorithm.
https://github.com/winstxnhdw/2d-separating-axis-theorem
collision-detection hyperplane-separation-theorem separating-axis-theorem two-dimensional
Last synced: 24 days ago
JSON representation
C++ implementation of a 2D separating axis algorithm.
- Host: GitHub
- URL: https://github.com/winstxnhdw/2d-separating-axis-theorem
- Owner: winstxnhdw
- Created: 2021-09-22T06:43:01.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2024-04-23T15:56:45.000Z (9 months ago)
- Last Synced: 2024-10-30T09:14:13.430Z (2 months ago)
- Topics: collision-detection, hyperplane-separation-theorem, separating-axis-theorem, two-dimensional
- Language: C++
- Homepage:
- Size: 33.2 KB
- Stars: 2
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# 2d-separating-axis-theorem
This repository contains a simple C++ implementation of a 2D separating axis algorithm. The algorithm does not compute the [Minimum Translation Vector (MTV)](https://dyn4j.org/2010/01/sat/#sat-mtv) as it is not within my use case. For more information, read [here](https://gamedevelopment.tutsplus.com/tutorials/collision-detection-using-the-separating-axis-theorem--gamedev-169).
> **Warning**: The comparing polygons must have an equal number of vertices. This does not necessarily have to be the case but I didn't have time to write that feature.
```yaml
:param bounds_a: (vector) vertices of polygon A
:param bounds_b: (vector) vertices of polygon B:return isIntersecting: (bool) true if the two polygons are intersecting
```## Test
```bash
g++ main.cpp
./a.out
```## Example
The following snippet is an example used in actual production.
```c++
for (size_t j = 0; j < static_obstacles_set.size(); j++) {
const std::vector static_obstacle = {
static_obstacles_set[j].points[0],
static_obstacles_set[j].points[1],
static_obstacles_set[j].points[2],
static_obstacles_set[j].points[3]
};const bool isIntersecting = separating_axis_intersect(vehicle_bounds, static_obstacle);
if (intersects) {
path.is_blocked = true;
path.is_static_obstacle = true;
}
}
```