-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtvector.cpp
104 lines (89 loc) · 3.22 KB
/
tvector.cpp
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#include "tvector.h"
//---------------------------------------------------------------------------------------------------
TVector TVector::vecCrossProd(const TVector& _tvVec) const
{
return TVector(dY*_tvVec.dZ - dZ*_tvVec.dY, dZ*_tvVec.dX - dX*_tvVec.dZ, dX*_tvVec.dY - dY*_tvVec.dX);
}
//---------------------------------------------------------------------------------------------------
double operator*(const TVector& _tvVec1, const TVector& _tvVec2)
{
return _tvVec1.dX*_tvVec2.dX + _tvVec1.dY*_tvVec2.dY + _tvVec1.dZ*_tvVec2.dZ;
}
//---------------------------------------------------------------------------------------------------
TVector operator*(const double _dMul, const TVector& _tvVec)
{
return _tvVec*_dMul;
}
//---------------------------------------------------------------------------------------------------
TVector TVector::operator-() const //unary minus
{
return TVector(-dX, -dY, -dZ);
}
//---------------------------------------------------------------------------------------------------
TVector TVector::operator+(const TVector& _tvVec) const
{
return TVector(dX + _tvVec.dX, dY + _tvVec.dY, dZ + _tvVec.dZ);
}
//---------------------------------------------------------------------------------------------------
TVector TVector::operator-(const TVector& _tvVec) const //binary minus
{
return TVector(*this) + (-_tvVec);
}
//---------------------------------------------------------------------------------------------------
TVector TVector::operator*(const double& _dMul) const
{
return TVector(dX*_dMul, dY*_dMul, dZ*_dMul);
}
//---------------------------------------------------------------------------------------------------
TVector TVector::operator/(const double& _dDiv) const
{
return TVector(dX/_dDiv, dY/_dDiv, dZ/_dDiv);
}
//---------------------------------------------------------------------------------------------------
TVector& TVector::operator+=(const TVector& _tvVec)
{
dX += _tvVec.dX;
dY += _tvVec.dY;
dZ += _tvVec.dZ;
return *this;
}
//---------------------------------------------------------------------------------------------------
TVector& TVector::operator-=(const TVector& _tvVec)
{
dX -= _tvVec.dX;
dY -= _tvVec.dY;
dZ -= _tvVec.dZ;
return *this;
}
//---------------------------------------------------------------------------------------------------
TVector& TVector::operator*=(const double& _dMul)
{
dX *= _dMul;
dY *= _dMul;
dZ *= _dMul;
return *this;
}
//---------------------------------------------------------------------------------------------------
TVector& TVector::operator/=(const double& _dDiv)
{
dX /= _dDiv;
dY /= _dDiv;
dZ /= _dDiv;
return *this;
}
//---------------------------------------------------------------------------------------------------
double TVector::dLength() const
{
return sqrt(dLength_SQR());
}
//---------------------------------------------------------------------------------------------------
double TVector::dLength_SQR() const
{
return (*this)*(*this);
}
//---------------------------------------------------------------------------------------------------
void TVector::Normalize()
{
(*this) /= dLength();
}
//---------------------------------------------------------------------------------------------------