57 lines
958 B
C++
57 lines
958 B
C++
#ifndef POSITION_H
|
|
#define POSITION_H
|
|
|
|
#include "BASICS.h"
|
|
|
|
class Vector {
|
|
|
|
public:
|
|
|
|
double x;
|
|
|
|
double y;
|
|
|
|
double length;
|
|
|
|
Vector() :
|
|
x(0.0), y(0.0), length(0.0) {
|
|
// nothing
|
|
}
|
|
|
|
Vector(double x, double y) :
|
|
x(x), y(y), length(sqrt(x * x + y * y)) {
|
|
// nothing
|
|
}
|
|
|
|
static Vector polar(long degrees, double length) {
|
|
double radians = (double) degrees * DEG_TO_RAD;
|
|
return {
|
|
cos(radians) * length,
|
|
sin(radians) * length,
|
|
};
|
|
}
|
|
|
|
Vector plus(double _x, double _y) const {
|
|
return {x + _x, y + _y};
|
|
}
|
|
|
|
Vector plus(Vector vector) const {
|
|
return {x + vector.x, y + vector.y};
|
|
}
|
|
|
|
Vector minus(double _x, double _y) const {
|
|
return {x - _x, y - _y};
|
|
}
|
|
|
|
Vector minus(Vector vector) const {
|
|
return {x - vector.x, y - vector.y};
|
|
}
|
|
|
|
Vector multiply(double i) const {
|
|
return {x * i, y * i};
|
|
}
|
|
|
|
};
|
|
|
|
#endif
|