Revision 3cae40b9
utility/vector.h | ||
---|---|---|
84 | 84 |
for (int i = 0; i < N; i++) |
85 | 85 |
res += p_vec[i] * p_vec[i]; |
86 | 86 |
|
87 |
if(isnan(res)) |
|
88 |
return 0; |
|
89 | 87 |
return sqrt(res); |
90 | 88 |
} |
91 | 89 |
|
92 | 90 |
void normalize() |
93 | 91 |
{ |
94 | 92 |
double mag = magnitude(); |
95 |
if (fabs(mag) <= 0.0001)
|
|
93 |
if (isnan(mag) || mag == 0.0)
|
|
96 | 94 |
return; |
97 | 95 |
|
98 |
int i; |
|
99 |
for(i = 0; i < N; i++) |
|
100 |
p_vec[i] = p_vec[i]/mag; |
|
96 |
for (int i = 0; i < N; i++) |
|
97 |
p_vec[i] /= mag; |
|
101 | 98 |
} |
102 | 99 |
|
103 | 100 |
double dot(const Vector& v) const |
Also available in: Unified diff