-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvector.cpp
76 lines (59 loc) · 1.26 KB
/
vector.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
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
73
74
75
//
// Created by Wangdawei on 2018/11/22.
//
#include <cmath>
#include "vector.h"
double Vec::getX() const {
return this->x;
}
double Vec::getY() const {
return y;
}
Vec::Vec(double x, double y) {
this->x = x;
this->y = y;
}
Vec Vec::operator+(Vec v) const {
return Vec(x + v.getX(), y + v.getY());
}
Vec Vec::operator-(Vec v) const {
return Vec(x - v.getX(), y - v.getY());
}
Vec Vec::operator*(double k) const {
return Vec(k * x, k * y);
}
double Vec::operator*(Vec v) const {
return x * v.getX() + y * v.getY();
}
Vec Vec::operator<<(double angle) const {
Vec a1(cos(angle), -sin(angle)), a2(sin(angle), cos(angle));
return Vec(a1 * (*this), a2 * (*this));
}
Vec Vec::operator>>(double angle) const {
return (*this) << (-angle);
}
Vec &Vec::operator=(Vec v) {
// Vec ret(v.getX(),v.getY());
this->x = v.getX();
this->y = v.getY();
return *this;
}
Vec &Vec::operator+=(Vec v) {
this->x += v.getX();
this->y += v.getY();
return *this;
}
Vec Vec::operator-() const {
return Vec(-x, -y);
}
Vec &Vec::operator-=(Vec v) {
(*this) += (-v);
return (*this);
}
Vec operator*(double k, Vec v) {
return v * k;
}
Vec &Vec::operator*=(double k) {
(*this) = (*this) * k;
return *this;
}