Locus No Pilotus
Project of four first grade MIPT DAFE/RSE students (for engineering practical work in the second semester) in Qt C++
Loading...
Searching...
No Matches
obstacles.h
Go to the documentation of this file.
1#pragma once
2
3// std libs:
4#include <memory>
5#include <vector>
6
7// our code libs:
8#include "lib/infinity.h"
9#include "lib/point.h"
10
11using lib::inf;
12using lib::precision;
13
14namespace math {
15
16/// @brief Прямая вида ax+by+c=0
18 LinearFunction(double a, double b, double c)
19 : a_coef{a}, b_coef{b}, c_coef{c} {}
20
21 LinearFunction(const lib::Point& point1, const lib::Point& point2) {
22 a_coef = point2.y - point1.y;
23 b_coef = -(point2.x - point1.x);
24 c_coef =
25 (point2.x - point1.x) * point1.y - (point2.y - point1.y) * point1.x;
26 }
27
28 double Substitute(const lib::Point& p) const {
29 return a_coef * p.x + b_coef * p.y + c_coef;
30 }
31
33
34 bool operator==(const LinearFunction& other) const {
35 double proportion = ((std::abs(a_coef) >= precision) &&
36 (std::abs(other.a_coef) >= precision))
37 ? other.a_coef / a_coef
38 : other.b_coef / b_coef;
39 return (std::abs(other.a_coef - proportion * a_coef) < precision) &&
40 (std::abs(other.b_coef - proportion * b_coef) < precision) &&
41 (std::abs(other.c_coef - proportion * c_coef) < precision);
42 }
43};
44
45/// @brief Точка с геометрическими связями
46struct Point : public lib::Point {
47 Point() = default;
48
49 Point(const lib::Point& p) : lib::Point(p) {}
50
51 Point(double xx, double yy) : lib::Point{xx, yy} {}
52
53 // Вторая точка касательной
54 std::shared_ptr<lib::Point> another_tangent_point = nullptr;
55};
56
57/// @brief Круговое препятствие
59 public:
60 /**
61 * @brief Инициализирует экземпляр CircleObstacle
62 * @param center: центр круга
63 * @param radius: радиус круга
64 */
65 CircleObstacle(Point center, double radius)
66 : center_{center}, radius_{radius} {}
67
69
70 Point GetCenter() const { return center_; }
71
72 double GetRadius() const { return radius_; }
73
74 std::vector<Point> GetTangentPoints() { return tangent_points_; }
75
76 void AddTangentPoint(const Point& tangent_point) {
77 tangent_points_.push_back(tangent_point);
78 }
79
80 bool operator==(const CircleObstacle& other) {
81 return (center_ == other.center_ &&
82 std::abs(radius_ - other.radius_) < precision);
83 }
84
85 bool operator!=(const CircleObstacle& other) {
86 return (center_ != other.center_ ||
87 std::abs(radius_ - other.radius_) >= precision);
88 }
89
90 private:
92
93 double radius_;
94
95 // Точки касания
96 std::vector<Point> tangent_points_;
97};
98
99/// @brief Многоугольное препятствие
101 public:
102 PolygonObstacle() = default;
103 /**
104 * @brief Инициализирует экземпляр PolygonObstacle
105 * @param vertexes: вершины многоугольника
106 */
107 PolygonObstacle(const std::vector<Point>& vertexes) : vertexes_{vertexes} {
108 center_ = Point(0, 0);
109 for (auto& elem : vertexes_) {
110 center_.x += elem.x;
111 center_.y += elem.y;
112 }
113 center_.x /= (double)vertexes_.size();
114 center_.y /= (double)vertexes_.size();
115 }
116
117 Point GetCenter() const { return center_; }
118
119 std::vector<Point> GetVertexes() const { return vertexes_; }
120
121 std::vector<Point> GetTangentPoints() { return tangent_points_; }
122
123 void AddTangentPoint(const Point& tangent_point) {
124 tangent_points_.push_back(tangent_point);
125 }
126
127 bool operator==(const PolygonObstacle& other) {
128 return vertexes_ == other.vertexes_;
129 }
130
131 bool operator!=(const PolygonObstacle& other) {
132 return vertexes_ != other.vertexes_;
133 }
134
135 private:
136 // Геометричекий центр вершин
138
139 // Вершины
140 std::vector<Point> vertexes_;
141
142 // Точки касания
143 std::vector<Point> tangent_points_;
144};
145
146} // namespace math
Круговое препятствие
Definition obstacles.h:58
bool operator==(const CircleObstacle &other)
Definition obstacles.h:80
Point center_
Definition obstacles.h:91
CircleObstacle()
Definition obstacles.h:68
std::vector< Point > tangent_points_
Definition obstacles.h:96
Point GetCenter() const
Definition obstacles.h:70
double GetRadius() const
Definition obstacles.h:72
double radius_
Definition obstacles.h:93
CircleObstacle(Point center, double radius)
Инициализирует экземпляр CircleObstacle.
Definition obstacles.h:65
void AddTangentPoint(const Point &tangent_point)
Definition obstacles.h:76
std::vector< Point > GetTangentPoints()
Definition obstacles.h:74
bool operator!=(const CircleObstacle &other)
Definition obstacles.h:85
Многоугольное препятствие
Definition obstacles.h:100
bool operator==(const PolygonObstacle &other)
Definition obstacles.h:127
PolygonObstacle(const std::vector< Point > &vertexes)
Инициализирует экземпляр PolygonObstacle.
Definition obstacles.h:107
Point center_
Definition obstacles.h:137
void AddTangentPoint(const Point &tangent_point)
Definition obstacles.h:123
std::vector< Point > vertexes_
Definition obstacles.h:140
std::vector< Point > GetVertexes() const
Definition obstacles.h:119
std::vector< Point > tangent_points_
Definition obstacles.h:143
std::vector< Point > GetTangentPoints()
Definition obstacles.h:121
Point GetCenter() const
Definition obstacles.h:117
bool operator!=(const PolygonObstacle &other)
Definition obstacles.h:131
Definition base.h:10
constexpr double inf
Infinity.
Definition infinity.h:9
constexpr double precision
Definition point.h:11
Definition adjacency_matrix.cpp:7
Математическая точка
Definition point.h:16
double y
Definition point.h:18
double x
Definition point.h:17
Прямая вида ax+by+c=0.
Definition obstacles.h:17
double a_coef
Definition obstacles.h:32
bool operator==(const LinearFunction &other) const
Definition obstacles.h:34
LinearFunction(const lib::Point &point1, const lib::Point &point2)
Definition obstacles.h:21
double c_coef
Definition obstacles.h:32
LinearFunction(double a, double b, double c)
Definition obstacles.h:18
double b_coef
Definition obstacles.h:32
double Substitute(const lib::Point &p) const
Definition obstacles.h:28
Точка с геометрическими связями
Definition obstacles.h:46
Point()=default
Point(double xx, double yy)
Definition obstacles.h:51
std::shared_ptr< lib::Point > another_tangent_point
Definition obstacles.h:54
Point(const lib::Point &p)
Definition obstacles.h:49