-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestvec2.cpp
More file actions
65 lines (64 loc) · 1.11 KB
/
Copy pathtestvec2.cpp
File metadata and controls
65 lines (64 loc) · 1.11 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
#include <iostream>
#include <math.h>
class VEC2
{
public:
float x, y;
VEC2(float X, float Y)
{
x = X;
y = Y;
}
VEC2()
{
x = 0.;
y = 0.;
}
VEC2 operator+(VEC2 const &obj)
{
VEC2 temp;
temp.x = x + obj.x;
temp.y = y + obj.y;
return temp;
}
VEC2 operator-(VEC2 const &obj)
{
VEC2 temp;
temp.x = x - obj.x;
temp.y = y - obj.y;
return temp;
}
VEC2 operator*(float const &a)
{
VEC2 temp;
temp.x = a * x;
temp.y = a * y;
return temp;
}
VEC2 operator/(float const &a)
{
VEC2 temp;
temp.x = x / a;
temp.y = y / a;
return temp;
}
VEC2 operator+=(VEC2 const &obj)
{
x += obj.x;
y += obj.y;
}
float mag()
{
return sqrt(pow(x, 2) + pow(y, 2));
}
};
int main()
{
VEC2 a(3, 4 );
// VEC2 b = a;
// b = b / 2;
// VEC2 c;
// std::cout << b.x << " " << b.y;
// std::cout<<a.mag();
std::cout<< pow((a/a.mag()).x,2) + pow((a/a.mag()).y,2);
}