Thunderbots Project
Loading...
Searching...
No Matches
trajectory_obstacle.hpp
1#pragma once
2
3#include "software/ai/navigator/obstacle/geom_obstacle.hpp"
4#include "software/ai/navigator/trajectory/trajectory_path.h"
5#include "software/geom/algorithms/contains.h"
6#include "software/geom/algorithms/distance.h"
7#include "software/geom/algorithms/intersects.h"
8
9template <typename GEOM_TYPE>
10class TrajectoryObstacle : public GeomObstacle<GEOM_TYPE>
11{
12 public:
13 TrajectoryObstacle() = delete;
14
21 explicit TrajectoryObstacle(const GEOM_TYPE& geom, TrajectoryPath traj);
22
23 bool contains(const Point& p, const double t_sec = 0) const override;
24 double distance(const Point& p, const double t_sec = 0) const override;
25 double signedDistance(const Point& p, const double t_sec = 0) const override;
26 bool intersects(const Segment& segment, const double t_sec = 0) const override;
27
28 private:
29 const TrajectoryPath traj_;
30};
31
32
33template <typename GEOM_TYPE>
35 TrajectoryPath traj)
36 : GeomObstacle<GEOM_TYPE>(geom), traj_(std::move(traj))
37{
38}
39
40template <typename GEOM_TYPE>
41bool TrajectoryObstacle<GEOM_TYPE>::contains(const Point& p, const double t_sec) const
42{
43 if (t_sec == 0)
44 {
45 return ::contains(this->geom_, p);
46 }
47 else
48 {
49 // Instead of shifting the obstacle, we will shift the point
50 // in the opposite direction of the motion of obstacle
51 const Vector displacement = traj_.getPosition(t_sec) - traj_.getPosition(0);
52 return ::contains(this->geom_, p - displacement);
53 }
54}
55
56template <typename GEOM_TYPE>
57double TrajectoryObstacle<GEOM_TYPE>::distance(const Point& p, const double t_sec) const
58{
59 if (t_sec == 0)
60 {
61 return ::distance(this->geom_, p);
62 }
63 else
64 {
65 // Instead of shifting the obstacle, we will shift the point
66 // in the opposite direction of the motion of obstacle
67 const Vector displacement = traj_.getPosition(t_sec) - traj_.getPosition(0);
68 return ::distance(this->geom_, p - displacement);
69 }
70}
71
72template <typename GEOM_TYPE>
74 const double t_sec) const
75{
76 if (t_sec == 0)
77 {
78 return ::signedDistance(this->geom_, p);
79 }
80 else
81 {
82 // Instead of shifting the obstacle, we will shift the point
83 // in the opposite direction of the motion of obstacle
84 const Vector displacement = traj_.getPosition(t_sec) - traj_.getPosition(0);
85 return ::signedDistance(this->geom_, p - displacement);
86 }
87}
88
89template <typename GEOM_TYPE>
91 const double t_sec) const
92{
93 if (t_sec == 0)
94 {
95 return ::intersects(this->geom_, segment);
96 }
97 else
98 {
99 // Instead of shifting the obstacle, we will shift the point
100 // in the opposite direction of the motion of obstacle
101 const Vector displacement = traj_.getPosition(t_sec) - traj_.getPosition(0);
102 return ::intersects(this->geom_, segment - displacement);
103 }
104}
Definition geom_obstacle.hpp:12
Definition point.h:14
Definition segment.h:7
Definition trajectory_obstacle.hpp:11
bool contains(const Point &p, const double t_sec=0) const override
Definition trajectory_obstacle.hpp:41
double signedDistance(const Point &p, const double t_sec=0) const override
Definition trajectory_obstacle.hpp:73
bool intersects(const Segment &segment, const double t_sec=0) const override
Definition trajectory_obstacle.hpp:90
double distance(const Point &p, const double t_sec=0) const override
Definition trajectory_obstacle.hpp:57
Definition trajectory_path.h:19
Definition vector.h:12