-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvector.h
More file actions
33 lines (27 loc) · 695 Bytes
/
vector.h
File metadata and controls
33 lines (27 loc) · 695 Bytes
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
/**
* Vector class
*/
#ifndef _VECTOR_H_
#define _VECTOR_H_
#define TOLERANCE 0.00001
class Vector {
public:
double x, y, z;
Vector(double a, double b, double c) {
x = a; y = b; z = c;
}
Vector() { }
Vector operator+(Vector v) {
return Vector(x+v.x,y+v.y,z+v.z);
}
void normalize() {
double mag_squared = x * x + y * y + z * z;
if (fabs(mag_squared) > TOLERANCE && fabs(mag_squared - 1.0) > TOLERANCE) {
double mag = sqrt(mag_squared);
x /= mag;
y /= mag;
z /= mag;
}
}
};
#endif // _VECTOR_H_