49 lines
1.0 KiB
C++
49 lines
1.0 KiB
C++
|
#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);
|
||
|
}
|