-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVec2D.h
77 lines (62 loc) · 1.01 KB
/
Vec2D.h
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
76
77
#ifndef VEC2D
#define VEC2D
#include <iostream>
#include <algorithm>
#include <math.h>
#include <random>
#include <chrono>
using namespace std;
template <class Type> class Vec {
// Data
public:
Type x,y;
public:
// Constructors
Vec() { }
Vec(const Type a, const Type b) {
x=a;
y=b;
}
void set_values(const Type a, const Type b) {
x=a;
y=b;
}
void randomize(double s) {
x=cos(s);
y=sin(s);
}
Type VProd() {
return (x*y);
}
Type VLen() {
return sqrt(x*x+y*y);
}
Type VLenSQ() {
return (x*x+y*y);
}
Type VCsum() {
return (x+y);
}
Vec<Type> operator+(const Vec<Type> &v) {
Type a = x+v.x;
Type b = y+v.y;
return Vec(a,b);
}
Vec<Type> operator-(const Vec<Type> &v) {
Type a = x-v.x;
Type b = y-v.y;
return Vec(a,b);
}
double operator*(const Vec<Type> v) {
return (x*v.x+y*v.y);
}
Vec<Type> operator*(Type s) {
Type a = x*s;
Type b = y*s;
return Vec(a,b);
}
friend Vec<Type> operator*(Type s,Vec<Type> v) {
return Vec<Type>(s*v.x,s*v.y);
}
};
#endif