Giter Club home page Giter Club logo

2d-separating-axis-theorem's Introduction

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) as it is not within my use case. For more information, read here.

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.

:param bounds_a:            (vector<x, y>) vertices of polygon A
:param bounds_b:            (vector<x, y>) vertices of polygon B

:return isIntersecting:     (bool) true if the two polygons are intersecting

Test

g++ main.cpp
./a.out

Example

The following snippet is an example used in actual production.

for (size_t j = 0; j < static_obstacles_set.size(); j++) {
    const std::vector<Vector2> 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;
    }
}

2d-separating-axis-theorem's People

Contributors

winstxnhdw avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Forkers

jiansheng72

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.