This repository was archived by the owner on Jun 10, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVector.h
More file actions
75 lines (52 loc) · 1.82 KB
/
Copy pathVector.h
File metadata and controls
75 lines (52 loc) · 1.82 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
66
67
68
69
70
71
72
73
74
75
// Vector.h: interface for the Vector class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_VECTOR_H__C2EAE644_668E_4AF3_815D_94C8FEB090B6__INCLUDED_)
#define AFX_VECTOR_H__C2EAE644_668E_4AF3_815D_94C8FEB090B6__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include <cmath>
class Vector
{
public:
Vector(double x = 0.0, double y = 0.0, double z = 0.0) : x(x), y(y), z(z) {};
Vector(const Vector& v) : x(v.x), y(v.y), z(v.z) {};
virtual ~Vector() {};
union {
double coordinate[3];
struct {
double x;
double y;
double z;
};
};
Vector operator - (const Vector& v) const { return Vector(x - v.x,y - v.y,z - v.z); };
Vector operator + (const Vector& v) const { return Vector(x + v.x,y + v.y,z + v.z); }
Vector& operator += (const Vector& v) { x += v.x; y += v.y; z += v.z; return *this; };
Vector& operator -= (const Vector& v) { x -= v.x; y -= v.y; z -= v.z; return *this; };
Vector& operator *= (double a) { x *= a; y *= a; z *= a; return *this; };
Vector& operator /= (double a) { x /= a; y /= a; z /= a; return *this; };
Vector operator * (const Vector& v) { return Vector(x*v.x,y*v.y,z*v.z); };
bool operator == (const Vector& v) { return ((v.x == x) && (v.y == y) && (v.z == z)); };
double getLength(void) {
return sqrt(x*x + y*y + z*z);
}
};
inline Vector operator * (const Vector& v,double a)
{
return Vector(v.x*a,v.y*a,v.z*a);
}
inline Vector operator * (double a,const Vector& v)
{
return Vector(v.x*a,v.y*a,v.z*a);
}
inline Vector operator / (const Vector& v,double a)
{
return Vector(v.x/a,v.y/a,v.z/a);
}
inline Vector operator / (double a,const Vector& v)
{
return Vector(v.x/a,v.y/a,v.z/a);
}
#endif // !defined(AFX_VECTOR_H__C2EAE644_668E_4AF3_815D_94C8FEB090B6__INCLUDED_)