-
Notifications
You must be signed in to change notification settings - Fork 2
/
coordinate.cpp
43 lines (35 loc) · 955 Bytes
/
coordinate.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include "coordinate.h"
#include "vector.h"
#include <iostream>
#include <math.h>
Coordinate::Coordinate() {
x = 0;
y = 0;
}
Coordinate::Coordinate( double x, double y ) {
this->x = x;
this->y = y;
}
Coordinate Coordinate::operator+( const Vector& vector ) {
Coordinate result;
result.x = x + cos( vector.angle ) * vector.norm;
result.y = y + sin( vector.angle ) * vector.norm;
return result;
}
Coordinate Coordinate::operator+( const Coordinate& other ) {
return Coordinate( x + other.x, y + other.y );
}
Coordinate Coordinate::operator*( const double& d ) {
return Coordinate( x * d, y * d );
}
Coordinate Coordinate::operator/( const double& d ) {
return Coordinate( x / d, y / d );
}
void Coordinate::print() {
std::cout << x << "\t" << y << std::endl;
}
double Coordinate::distance( const Coordinate& other ) const {
double dx = other.x - x;
double dy = other.y - y;
return sqrt( dx * dx + dy * dy );
}