-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathVector.cpp
More file actions
60 lines (49 loc) · 1.29 KB
/
Vector.cpp
File metadata and controls
60 lines (49 loc) · 1.29 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
#pragma once
#include <cmath>
class Vector{
private:
float x, y;
public:
Vector(){}
Vector(float x, float y){
set(x, y);
}
void set(float x, float y){
this->x = x;
this->y = y;
}
float getX(){
return this->x;
}
float getY(){
return this->y;
}
float getMagnitute(int square = 0){
return square ? pow(x,2) + pow(y,2) : sqrt(pow(x,2) + pow(y,2));
}
float getArgument(){
return atan(this->y/this->x);
}
float distanceFrom(Vector v){
return sqrt(pow((this->x - v.x), 2) + pow((this->y - v.y), 2));
}
float dotProduct(Vector v){
return (this->x * v.x + this->y * v.y);
}
Vector multiply(float i){
Vector u(this->x * i, this->y * i);
return u;
}
Vector normalize(){
return this->multiply(1/this->getMagnitute());
}
Vector sub(Vector v){
Vector u(this->x - v.x, this->y - v.y);
return u;
}
Vector add(Vector v){
Vector u(this->x + v.x, this->y + v.y);
return u;
}
friend class Game ;
};