-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVec2D.cpp
More file actions
72 lines (55 loc) · 1.06 KB
/
Vec2D.cpp
File metadata and controls
72 lines (55 loc) · 1.06 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include"main.h"
#include"matplotlibcpp.h"
#include"Vec2D.h"
//Constructor and destructor methods
vec2d::vec2d(){
x = 0;
y = 0;
}
vec2d::vec2d(double a, double b){
x = a;
y = b;
}
vec2d::~vec2d(){
}
//Methods
double vec2d::get_x(){
return this->x;
}
double vec2d::get_y(){
return this->y;
}
void vec2d::set_x(double a){
x = a;
}
void vec2d::set_y(double b){
y = b;
}
void vec2d::add(vec2d vec){
x = this->x + vec.get_x();
y = this->y + vec.get_y();
}
void vec2d::sub(vec2d vec){
x = this->x - vec.get_x();
y = this->y - vec.get_y();
}
void vec2d::scale(double a){
x = this->x * a;
y = this->y * a;
}
//Operators
vec2d vec2d::operator+(vec2d vec){
vec2d vec2(this->x + vec.get_x(), this->y + vec.get_y());
return vec2;
}
vec2d vec2d::operator-(vec2d vec){
vec2d vec2(this->x - vec.get_x(), this->y - vec.get_y());
return vec2;
}
vec2d vec2d::operator*(double a){
vec2d vec2(this->x * a, this->y * a);
return vec2;
}
double vec2d::len(){
return sqrt(pow(this->x, 2) + pow(this->y, 2));
}