1#ifndef TATOOINE_SEPARATING_AXIS_THEOREM_H
2#define TATOOINE_SEPARATING_AXIS_THEOREM_H
11template <
typename Real>
15 Real min0, min1, max0, max1;
16 min0 = min1 = std::numeric_limits<Real>::infinity();
17 max0 = max1 = -std::numeric_limits<Real>::infinity();
19 for (
auto const& v : polygon0) {
20 auto const projection =
dot(v, n);
21 min0 = std::min(min0, projection);
22 max0 = std::max(max0, projection);
24 for (
auto const& v : polygon1) {
25 auto const projection =
dot(v, n);
26 min1 = std::min(min1, projection);
27 max1 = std::max(max1, projection);
29 return !(max0 >= min1 && max1 >= min0);
34template <
typename Real>
38 using vec_list = std::vector<vec_t>;
40 normals.reserve(
size(polygon0) +
size(polygon1));
43 for (
size_t i = 0; i <
size(polygon0) - 1; ++i) {
44 e = polygon0[i + 1] - polygon0[i];
45 normals.push_back(vec_t{-e(1), e(0)});
47 for (
size_t i = 0; i <
size(polygon1) - 1; ++i) {
48 e = polygon1[i + 1] - polygon1[i];
49 normals.push_back(vec_t{-e(1), e(0)});
51 e = polygon0.front() - polygon0.back();
52 normals.push_back(vec_t{-e(1), e(0)});
53 e = polygon1.front() - polygon1.back();
54 normals.push_back(vec_t{-e(1), e(0)});
56 for (
auto const& n : normals) {
Definition: algorithm.h:6
auto is_separating_axis(vec< Real, 2 > const &n, std::vector< vec< Real, 2 > > const &polygon0, std::vector< vec< Real, 2 > > const &polygon1)
Return true if n is a separating axis of polygon0 and polygon1.
Definition: separating_axis_theorem.h:12
auto size(vec< ValueType, N > const &v)
Definition: vec.h:148
constexpr auto dot(base_tensor< Tensor0, T0, N > const &lhs, base_tensor< Tensor1, T1, N > const &rhs)
Definition: tensor_operations.h:120
auto has_separating_axis(std::vector< vec< Real, 2 > > const &polygon0, std::vector< vec< Real, 2 > > const &polygon1) -> bool
Definition: separating_axis_theorem.h:35