use vector for choose direction

This commit is contained in:
2023-12-28 14:57:13 +01:00
parent 17ba18a200
commit 633592a4ea
7 changed files with 162 additions and 30 deletions

49
Vector2D.cpp Normal file
View File

@@ -0,0 +1,49 @@
#include "Vector2D.h"
Vector2D::Vector2D(Point point) {
point_.x = point.x;
point_.y = point.y;
lenght_ = sqrt(pow(point.x, 2) + pow(point.y, 2));
angle_ = atan2(point.y, point.x);
}
Vector2D::Vector2D(double lenght, double angle) {
lenght_ = lenght;
angle_ = angle;
point_.x = lenght * cos(angle);
point_.y = lenght * sin(angle);
}
Vector2D::Point Vector2D::CreatePoint(double x, double y) {
Point p;
p.x = x;
p.y = y;
return p;
}
void Vector2D::normalize(double max) {
lenght_ = (1/lenght_);
point_.x = lenght_ * cos(angle_);
point_.y = lenght_ * sin(angle_);
}
Vector2D Vector2D::reverse() {
Point p;
p.x = -point_.x;
p.y = -point_.y;
return Vector2D(p);
}
Vector2D Vector2D::operator +(Vector2D v) const {
Point p;
p.x = point_.x + v.x();
p.y = point_.y + v.y();
return Vector2D(p);
}
Vector2D Vector2D::operator -(Vector2D v) const {
Point p;
p.x = point_.x - v.x();
p.y = point_.y - v.y();
return Vector2D(p);
}