| Bsoft 2.0.5 Bernard's software package

Vector3.h
Go to the documentation of this file.
1
10 #include <iostream>
11 #include <cmath>
12 #include <vector>
13
14 #include "math_util.h"
15 #include "utilities.h"
16
17 using namespace std;
18
19 #ifndef _Vector3_
20 #define _Vector3_
21
26 template <typename Type>
27 class Vector3 {
28 private:
29 Type data[3];
30 public:
31 Vector3() { data[0] = 0; data[1] = 0; data[2] = 0; }
32 Vector3(const Vector3& v) { data[0] = v.data[0]; data[1] = v.data[1]; data[2] = v.data[2]; }
33 Vector3(const Type x, const Type y, const Type z) { data[0] = x; data[1] = y; data[2] = z; }
34 template <typename T2>
35 Vector3(const vector<T2>& v) { for ( size_t i=0; i<3 && i<v.size(); i++ ) data[i] = v[i]; }
36 Vector3 operator=(const Type d) { data[0] = d; data[1] = 0; data[2] = 0; return *this; }
37 Vector3 operator=(const Vector3& v) {
38 data[0] = v.data[0]; data[1] = v.data[1]; data[2] = v.data[2];
39 return *this;
40 }
41 template <typename T2>
42 Vector3 operator=(const vector<T2>& v) {
43 for ( size_t i=0; i<3 && i<v.size(); i++ ) data[i] = v[i];
44 return *this;
45 }
46 Vector3 operator-() {
47 Vector3<Type> vn(-data[0], -data[1], -data[2]);
48 return vn;
49 }
50 Vector3 operator+=(const double d) {
51 for ( int i=0; i<3; i++ ) data[i] += Type(d);
52 return *this;
53 }
54 Vector3 operator+(const double d) {
55 Vector3<Type> vn(Type(data[0]+d), Type(data[1]+d), Type(data[2]+d));
56 return vn;
57 }
58 Vector3 operator+=(const Vector3& v) {
59 for ( int i=0; i<3; i++ ) data[i] += v.data[i];
60 return *this;
61 }
62 Vector3 operator+(const Vector3& v) {
63 Vector3<Type> vn(data[0]+v.data[0], data[1]+v.data[1], data[2]+v.data[2]);
64 return vn;
65 }
66 Vector3 operator-=(const double d) {
67 for ( int i=0; i<3; i++ ) data[i] -= Type(d);
68 return *this;
69 }
70 Vector3 operator-(const double d) {
71 Vector3<Type> vn(Type(data[0]-d), Type(data[1]-d), Type(data[2]-d));
72 return vn;
73 }
74 Vector3 operator-=(const Vector3& v) {
75 for ( int i=0; i<3; i++ ) data[i] -= v.data[i];
76 return *this;
77 }
78 Vector3 operator-(const Vector3& v) {
79 Vector3<Type> vn(data[0]-v.data[0], data[1]-v.data[1], data[2]-v.data[2]);
80 return vn;
81 }
82 Vector3 operator*=(const double d) {
83 for ( int i=0; i<3; i++ ) data[i] = Type(data[i] * d);
84 return *this;
85 }
86 Vector3 operator*(const double d) {
87 Vector3<Type> vn(Type(data[0] * d), Type(data[1] * d), Type(data[2] * d));
88 return vn;
89 }
90 Vector3 operator*=(const Vector3& v) { // Note that the order is important for vectors of different types
91 for ( int i=0; i<3; i++ ) data[i] *= v.data[i];
92 return *this;
93 }
94 Vector3 operator*(const Vector3& v) {
95 Vector3<Type> vn(data[0]*v.data[0], data[1]*v.data[1], data[2]*v.data[2]);
96 return vn;
97 }
98 Vector3 operator/=(const double d) {
99 if ( fabs(d) < 1e-30 ) return *this;
100 double div = 1/d;
101 for ( int i=0; i<3; i++ ) data[i] *= div;
102 return *this;
103 }
104 Vector3 operator/(const double d) {
105 Vector3<Type> vn(Type(data[0] / d), Type(data[1] / d), Type(data[2] / d));
106 return vn;
107 }
108 Vector3 operator/=(const Vector3& v) {
109 for ( int i=0; i<3; i++ ) data[i] /= v.data[i];
110 return *this;
111 }
112 Vector3 operator/(const Vector3& v) {
113 Vector3<Type> vn(data[0]/v.data[0], data[1]/v.data[1], data[2]/v.data[2]);
114 return vn;
115 }
116 bool operator==(const Vector3& v) {
117 int i, e(0);
118 for ( i=0; i<3; i++ ) e += ( data[i] == v.data[i] );
119 return ( e == 3 );
120 }
121 bool operator==(const double d) {
122 int i, e(0);
123 for ( i=0; i<3; i++ ) e += ( data[i] == d );
124 return ( e == 3 );
125 }
126 bool operator!=(const Vector3& v) {
127 int i, e(0);
128 for ( i=0; i<3; i++ ) e += ( data[i] == v.data[i] );
129 return ( e != 3 );
130 }
131 bool operator>(const double d) {
132 int i, e(0);
133 for ( i=0; i<3; i++ ) e += ( data[i] > d );
134 return ( e == 3 );
135 }
136 bool operator<(const double d) {
137 int i, e(0);
138 for ( i=0; i<3; i++ ) e += ( data[i] < d );
139 return ( e == 3 );
140 }
141 bool operator>(const Vector3& v) {
142 int i, e(0);
143 for ( i=0; i<3; i++ ) e += ( data[i] > v.data[i] );
144 return ( e == 3 );
145 }
146 bool operator<(const Vector3& v) {
147 int i, e(0);
148 for ( i=0; i<3; i++ ) e += ( data[i] < v.data[i] );
149 return ( e == 3 );
150 }
151 bool operator>=(const Vector3& v) {
152 int i, e(0);
153 for ( i=0; i<3; i++ ) e += ( data[i] >= v.data[i] );
154 return ( e == 3 );
155 }
156 bool operator<=(const Vector3& v) {
157 int i, e(0);
158 for ( i=0; i<3; i++ ) e += ( data[i] <= v.data[i] );
159 return ( e == 3 );
160 }
161 Type operator[](size_t i) const { while ( i>2 ) i-=3; return data[i]; }
162 Type& operator[](size_t i) { while ( i>2 ) i-=3; return data[i]; }
163 template <typename T2> operator Vector3<T2>() const {
164 return Vector3<T2>((T2)data[0], (T2)data[1], (T2)data[2]);
165 }
166 vector<double> array() {
167 return {data[0], data[1], data[2]};
168 }
169 Type min() {
170 Type d(data[0]);
171 if ( d > data[1] ) d = data[1];
172 if ( d > data[2] ) d = data[2];
173 return d;
174 }
175 Type max() {
176 Type d(data[0]);
177 if ( d < data[1] ) d = data[1];
178 if ( d < data[2] ) d = data[2];
179 return d;
180 }
181 Vector3 min(const double d) {
182 Vector3 vn(*this);
183 for ( int i=0; i<3; i++ ) if ( vn.data[i] > d ) vn.data[i] = (Type)d;
184 return vn;
185 }
186 Vector3 max(const double d) {
187 Vector3 vn(*this);
188 for ( int i=0; i<3; i++ ) if ( vn.data[i] < d ) vn.data[i] = (Type)d;
189 return vn;
190 }
191 Vector3 min(const Vector3& v) {
192 Vector3 vn(*this);
193 for ( int i=0; i<3; i++ ) if ( vn.data[i] > v.data[i] ) vn.data[i] = v.data[i];
194 return vn;
195 }
196 Vector3 max(const Vector3& v) {
197 Vector3 vn(*this);
198 for ( int i=0; i<3; i++ ) if ( vn.data[i] < v.data[i] ) vn.data[i] = v.data[i];
199 return vn;
200 }
201 Vector3 abs() {
202 Vector3 vn(*this);
203 for ( int i=0; i<3; i++ ) if ( data[i] < 0 ) vn.data[i] = -data[i];
204 return vn;
205 }
206 Vector3 floor(int places) {
207 Vector3 vn;
208 for ( int i=0; i<3; i++ ) vn.data[i] = bfloor(data[i], places);
209 return vn;
210 }
211 Vector3 round(int places) {
212 Vector3 vn;
213 for ( int i=0; i<3; i++ ) vn.data[i] = bround(data[i], places);
214 return vn;
215 }
216 Vector3 remainder(int divisor) {
217 Vector3 vn;
218 for ( int i=0; i<3; i++ ) vn.data[i] = fmod(data[i], divisor);
219 return vn;
220 }
221 double length2() { return (double)data[0]*data[0] + (double)data[1]*data[1] + (double)data[2]*data[2]; }
222 double length() { return sqrt(length2()); }
223 void length(double d) {
224 double len(length());
225 if ( len ) *this *= d/len;
226 }
227 double distance(const Vector3& v) { return (*this - v).length(); }
228 double distance2(const Vector3& v) { return (*this - v).length2(); }
229 Vector3 square_root() {
230 Vector3 v;
231 for ( int i=0; i<3; i++ ) v.data[i] = sqrt(data[i]);
232 return v;
233 }
234 double sum() { return (double)data[0] + (double)data[1] + (double)data[2]; }
235 double volume() { return (double)data[0]*data[1]*data[2]; }
236 double normalize() {
237 double len = length();
238 if ( len < 1e-30 ) {
239 // len = 1;
240 data[2] = 1;
241 } else {
242 double div = 1.0/len;
243 for ( int i=0; i<3; i++ ) data[i] *= div;
244 }
245 return len;
246 }
247 double scalar(const Vector3& v) const {
248 return (double)data[0]*v.data[0] + (double)data[1]*v.data[1] + (double)data[2]*v.data[2];
249 }
250 Vector3 cross(const Vector3& v) {
251 Vector3 vn((double)data[1]*v.data[2] - (double)data[2]*v.data[1],
252 (double)data[2]*v.data[0] - (double)data[0]*v.data[2],
253 (double)data[0]*v.data[1] - (double)data[1]*v.data[0]);
254 return vn;
255 }
256 template <typename T2>
257 double angle(Vector3<T2>& v) {
258 Vector3 v1(*this);
259 Vector3 v2(v);
260 v1.normalize();
261 v2.normalize();
262 double prod = v1.scalar(v2);
263 if ( prod > 1 ) prod = 1;
264 if ( prod < -1 ) prod = -1;
265 return(acos(prod));
266 }
267 Vector3 normal(Vector3& v1, Vector3& v2) {
268 Vector3 edge1 = *this - v1;
269 Vector3 edge2 = *this - v2;
270 Vector3 normal = edge1.cross(edge2);
271 normal.normalize();
272 return(normal);
273 }
274 bool notfinite() {
275 int e(0);
276 for ( int i=0; i<3; i++ ) e += isfinite(data[i]);
277 return ( e != 3 );
278 }
279 bool within(Vector3& v1, Vector3& v2) {
280 int i, e(0);
281 for ( i=0; i<3; i++ ) e += (data[i] >= v1.data[i]);
282 for ( i=0; i<3; i++ ) e += (data[i] <= v2.data[i]);
283 return ( e == 6 );
284 }
285 // friend Vector3<float> operator=(Vector3<double>& vd);
286 // friend Vector3<double> operator=(Vector3<float>& vf);
287 } ;
288
289 template <typename Type>
290 ostream& operator<<(ostream& output, Vector3<Type> vec) {
291 output.setf(ios::fixed, ios::floatfield);
292 output << vec[0] << tab << vec[1] << tab << vec[2];
293 return output;
294 }
295
296 template <typename Type>
297 ostream& operator<<(ostream& output, vector<Type> vec) {
298 output.setf(ios::fixed, ios::floatfield);
299 output << vec[0];
300 for ( auto it = vec.begin()+1; it != vec.end(); ++it )
301 cout << tab << *it;
302 return output;
303 }
304 /*
305 template <typename T1, typename T2>
306 //inline vector<T1> operator=(vector<T1> v, Vector3<T2> v3)
307 inline void operator=(vector<T1>& v, Vector3<T2> v3)
308 //inline vector<T1>::operator=(Vector3<T2> v3)
309 {
310 for ( long i = 0; i<3; ++i )
311 v[i] = v3[i];
312
313 return v;
314 }
315
316 template <typename T> operator vector<T>() const {
317 return Vector3<T2>((T2)data[0], (T2)data[1], (T2)data[2]);
318 }
319
320 template <typename T1, typename T2> operator vector<T1>(Vector3<T2> v3)
321 {
322 vector<T1> v(3);
323
324 for ( long i = 0; i<3; ++i )
325 v[i] = v3[i];
326
327 return v;
328 }
329 */
330 /*
331 template <typename T1, typename T2>
332 inline operator vector<T1>(vector<T2> v1) {
333 vector<T1> v(v1.size());
334
335 for ( long i = 0; i<v1.size(); ++i )
336 v[i] = T1(v1[i]);
337
338 return v;
339 }
340 */
341 /*
342 template <typename T1, typename T2>
343 inline void operator=(vector<T1>& v1, vector<T2> v2)
344 {
345 v1.reserve(v2.size());
346
347 for ( long i = 0; i<v1.size() && i<v2.size(); ++i )
348 v1[i] = T2(v2[i]);
349 }
350 */
351 template <typename T>
352 inline vector<T> operator-(vector<T> v1)
353 {
354 vector<T> v = v1;
355
356 for ( size_t i = 0; i<v1.size(); ++i )
357 v[i] = -v1[i];
358
359 return v;
360 }
361
362 template <typename T1, typename T2>
363 inline vector<T1> operator+(vector<T1> v1, vector<T2> v2)
364 {
365 vector<T1> v = v1;
366
367 for ( size_t i = 0; i<v1.size() && i<v2.size(); ++i )
368 v[i] = v1[i] + v2[i];
369
370 return v;
371 }
372
373 template <typename T1, typename T2>
374 inline vector<T1> operator+(vector<T1> v1, T2 v2)
375 {
376 vector<T1> v = v1;
377
378 for ( size_t i = 0; i<v1.size(); ++i )
379 v[i] = v1[i] + v2;
380
381 return v;
382 }
383
384 template <typename T1, typename T2>
385 inline void operator+=(vector<T1>& v1, vector<T2> v2)
386 {
387 for ( size_t i = 0; i<v1.size() && i<v2.size(); ++i )
388 v1[i] += v2[i];
389 }
390
391 template <typename T1, typename T2>
392 inline void operator+=(vector<T1>& v1, T2 v2)
393 {
394 for ( size_t i = 0; i<v1.size(); ++i )
395 v1[i] += v2;
396 }
397
398
399 template <typename T1, typename T2>
400 inline vector<T1> operator-(vector<T1> v1, vector<T2> v2)
401 {
402 vector<T1> v = v1;
403
404 for ( size_t i = 0; i<v1.size() && i<v2.size(); ++i )
405 v[i] = v1[i] - v2[i];
406
407 return v;
408 }
409
410 template <typename T1, typename T2>
411 inline vector<T1> operator-(vector<T1> v1, Vector3<T2>& v2)
412 {
413 for ( size_t i = 0; i<v1.size() && i<3; ++i )
414 v1[i] -= v2[i];
415
416 return v1;
417 }
418
419 template <typename T1, typename T2>
420 inline vector<T1> operator-(vector<T1> v1, T2 v2)
421 {
422 vector<T1> v(v1.size());
423
424 for ( size_t i = 0; i<v1.size(); ++i )
425 v[i] = v1[i] - v2;
426
427 return v;
428 }
429
430 template <typename T1, typename T2>
431 inline void operator-=(vector<T1>& v1, vector<T2> v2)
432 {
433 for ( size_t i = 0; i<v1.size() && i<v2.size(); ++i )
434 v1[i] -= v2[i];
435 }
436
437 template <typename T1, typename T2>
438 inline void operator-=(vector<T1>& v1, T2 v2)
439 {
440 for ( size_t i = 0; i<v1.size(); ++i )
441 v1[i] -= v2;
442 }
443
444 template <typename T1, typename T2>
445 inline vector<T1> operator*(vector<T1> v1, T2 v2)
446 {
447 vector<T1> v = v1;
448
449 for ( size_t i = 0; i<v1.size(); ++i )
450 v[i] = v1[i] * v2;
451
452 return v;
453 }
454
455 template <typename T1, typename T2>
456 inline void operator*=(vector<T1>& v1, T2 v2)
457 {
458 for ( size_t i = 0; i<v1.size(); ++i )
459 v1[i] *= v2;
460 }
461
462 template <typename T1, typename T2>
463 inline vector<T1> operator*(vector<T1> v1, vector<T2> v2)
464 {
465 vector<T1> v = v1;
466
467 for ( size_t i = 0; i<v1.size() && i<v2.size(); ++i )
468 v[i] = v1[i] * v2[i];
469
470 return v;
471 }
472
473 template <typename T1, typename T2>
474 inline void operator*=(vector<T1>& v1, vector<T2> v2)
475 {
476 for ( size_t i = 0; i<v1.size() && i<v2.size(); ++i )
477 v1[i] *= v2[i];
478 }
479
480 template <typename T1, typename T2>
481 inline vector<T1> operator/(vector<T1> v1, T2 v2)
482 {
483 vector<T1> v = v1;
484
485 for ( size_t i = 0; i<v1.size(); ++i )
486 v[i] = v1[i] / v2;
487
488 return v;
489 }
490
491 template <typename T1, typename T2>
492 inline void operator/=(vector<T1>& v1, T2 v2)
493 {
494 for ( size_t i = 0; i<v1.size(); ++i )
495 v1[i] /= v2;
496 }
497
498 template <typename T1, typename T2>
499 inline vector<T1> operator/(vector<T1> v1, vector<T2> v2)
500 {
501 vector<T1> v = v1;
502
503 for ( size_t i = 0; i<v1.size() && i<v2.size(); ++i )
504 v[i] = v1[i] / v2[i];
505
506 return v;
507 }
508
509 template <typename T1, typename T2>
510 inline void operator/=(vector<T1> v1, vector<T2> v2)
511 {
512 for ( size_t i = 0; i<v1.size() && i<v2.size(); ++i )
513 v1[i] /= v2[i];
514 }
515
516 template <typename T>
517 inline double length2(vector<T> v)
518 {
519 double len(0);
520
521 for ( auto it = v.begin(); it != v.end(); ++it )
522 len += *it * *it;
523
524 return len;
525 }
526
527 template <typename T>
528 inline double length(vector<T> v)
529 {
530 double len(length2(v));
531
532 return sqrt(len);
533 }
534
535 template <typename T1, typename T2>
536 inline double distance(vector<T1>& v1, vector<T2>& v2)
537 {
538 vector<T1> v = v1 - v2;
539
540 return length(v);
541 }
542
543
544 template <typename T>
545 inline T volume(vector<T> v)
546 {
547 T vol(1);
548
549 for ( auto it = v.begin(); it != v.end(); ++it )
550 vol *= *it;
551
552 return vol;
553 }
554
555 template <typename T>
556 inline vector<T> absolute(vector<T> v1)
557 {
558 vector<T> v(v1.size());
559
560 for ( size_t i = 0; i<v1.size(); ++i )
561 v[i] = fabs(v1[i]);
562
563 return v;
564 }
565
566 template <typename T1, typename T2>
567 inline vector<T1> vecmin(vector<T1> v1, vector<T2> v2)
568 {
569 vector<T1> v = v1;
570
571 for ( size_t i = 0; i<v1.size() && i<v2.size(); ++i )
572 if ( v1[i] > v2[i] ) v[i] = v2[i];
573
574 return v;
575 }
576
577 template <typename T1, typename T2>
578 inline vector<T1> vecmin(vector<T1> v1, T2 v2)
579 {
580 vector<T1> v = v1;
581
582 for ( size_t i = 0; i<v1.size(); ++i )
583 if ( v1[i] > v2 ) v[i] = v2;
584
585 return v;
586 }
587
588 template <typename T1, typename T2>
589 inline vector<T1> vecmax(vector<T1> v1, vector<T2> v2)
590 {
591 vector<T1> v = v1;
592
593 for ( size_t i = 0; i<v1.size() && i<v2.size(); ++i )
594 if ( v1[i] < v2[i] ) v[i] = v2[i];
595
596 return v;
597 }
598
599 template <typename T1, typename T2>
600 inline vector<T1> vecmax(vector<T1> v1, T2 v2)
601 {
602 vector<T1> v = v1;
603
604 for ( size_t i = 0; i<v1.size(); ++i )
605 if ( v1[i] < v2 ) v[i] = v2;
606
607 return v;
608 }
609
610 template <typename T1, typename T2>
611 inline double scalar(vector<T1>& v1, vector<T2>& v2)
612 {
613 double d(0);
614
615 for ( size_t i = 0; i<v1.size(); ++i )
616 d += v1[i] * v2[i];
617
618 return d;
619 }
620
621 template <typename T1, typename T2>
622 inline vector<T1> cross(vector<T1>& v1, vector<T2>& v2)
623 {
624 vector<T1> v(v1.size());
625
626 v[0] = v1[1]*v2[2] - v1[2]*v2[1];
627 v[1] = v1[2]*v2[0] - v1[0]*v2[2],
628 v[2] = v1[0]*v2[1] - v1[1]*v2[0];
629
630 return v;
631 }
632
642 template <typename Type>
643 inline Vector3<Type> operator/(double d, Vector3<Type> vec)
644 {
645 if ( vec[0] == 0 || vec[1] == 0 || vec[2] == 0 )
646 cerr << "Error: Zero elements in vector " << vec << endl;
647
648 return Vector3<Type>(d/vec[0], d/vec[1], d/vec[2]);
649 }
650
651 template <typename Type>
652 inline Vector3<Type> vector3_scalar_range(Vector3<Type> vec, double min, double max)
653 {
654 if ( max < min ) return(vec);
655
656 if ( vec[0] < min ) vec[0] = min;
657 if ( vec[0] > max ) vec[0] = max;
658 if ( vec[1] < min ) vec[1] = min;
659 if ( vec[1] > max ) vec[1] = max;
660 if ( vec[2] < min ) vec[2] = min;
661 if ( vec[2] > max ) vec[2] = max;
662
663 return vec;
664 }
665
666 template <typename T1, typename T2>
667 Vector3<T1> vector3_origin_to_shift(Vector3<T1> origin, Vector3<T2> size)
668 {
669 Vector3<double> h(size/2);
670
671 while ( origin[0] < -h[0] ) origin[0] += size[0];
672 while ( origin[1] < -h[1] ) origin[1] += size[1];
673 while ( origin[2] < -h[2] ) origin[2] += size[2];
674 while ( origin[0] > h[0] ) origin[0] -= size[0];
675 while ( origin[1] > h[1] ) origin[1] -= size[1];
676 while ( origin[2] > h[2] ) origin[2] -= size[2];
677
678 return origin;
679 }
680
681 template <typename T1, typename T2>
682 inline Vector3<T1> vector3_set_PBC(Vector3<T1> coord, Vector3<T2> box)
683 {
684 while ( coord[0] < 0 ) coord[0] += box[0];
685 while ( coord[1] < 0 ) coord[1] += box[1];
686 while ( coord[2] < 0 ) coord[2] += box[2];
687 while ( coord[0] >= box[0] ) coord[0] -= box[0];
688 while ( coord[1] >= box[1] ) coord[1] -= box[1];
689 while ( coord[2] >= box[2] ) coord[2] -= box[2];
690
691 return coord;
692 }
693
694 template <typename T1, typename T2>
695 inline Vector3<T1> vector3_difference_PBC(Vector3<T1>& v1, Vector3<T1>& v2, Vector3<T2>& box)
696 {
697 Vector3<T1> d = v1 - v2;
698
699 if ( box[0] - d[0] < d[0] ) d[0] -= box[0];
700 if ( box[0] + d[0] < -d[0] ) d[0] += box[0];
701 if ( box[1] - d[1] < d[1] ) d[1] -= box[1];
702 if ( box[1] + d[1] < -d[1] ) d[1] += box[1];
703 if ( box[2] - d[2] < d[2] ) d[2] -= box[2];
704 if ( box[2] + d[2] < -d[2] ) d[2] += box[2];
705
706 return d;
707 }
708
709
710 #endif
711
712
Vector3::operator[]
Type operator[](size_t i) const
Definition: Vector3.h:161
distance
double distance(vector< T1 > &v1, vector< T2 > &v2)
Definition: Vector3.h:536
Vector3::operator=
Vector3 operator=(const Type d)
Definition: Vector3.h:36
Vector3::cross
Vector3 cross(const Vector3 &v)
Definition: Vector3.h:250
Vector3::normal
Vector3 normal(Vector3 &v1, Vector3 &v2)
Definition: Vector3.h:267
Vector3::normalize
double normalize()
Definition: Vector3.h:236
Vector3::remainder
Vector3 remainder(int divisor)
Definition: Vector3.h:216
Vector3::length
double length()
Definition: Vector3.h:222
vector3_set_PBC
Vector3< T1 > vector3_set_PBC(Vector3< T1 > coord, Vector3< T2 > box)
Definition: Vector3.h:682
Vector3::operator/
Vector3 operator/(const double d)
Definition: Vector3.h:104
Vector3::operator[]
Type & operator[](size_t i)
Definition: Vector3.h:162
Vector3::operator-
Vector3 operator-()
Definition: Vector3.h:46
operator *
vector< T1 > operator *(vector< T1 > v1, T2 v2)
Definition: Vector3.h:445
Vector3::operator<
bool operator<(const double d)
Definition: Vector3.h:136
utilities.h
Header file for general utilities.
operator/
vector< T1 > operator/(vector< T1 > v1, T2 v2)
Definition: Vector3.h:481
Vector3::operator+
Vector3 operator+(const double d)
Definition: Vector3.h:54
Vector3::abs
Vector3 abs()
Definition: Vector3.h:201
operator *=
void operator *=(vector< T1 > &v1, T2 v2)
Definition: Vector3.h:456
Vector3::operator<=
bool operator<=(const Vector3 &v)
Definition: Vector3.h:156
Vector3::Vector3
Vector3(const Type x, const Type y, const Type z)
Definition: Vector3.h:33
Vector3::Vector3
Vector3()
Definition: Vector3.h:31
Vector3::operator-
Vector3 operator-(const Vector3 &v)
Definition: Vector3.h:78
Vector3::operator-
Vector3 operator-(const double d)
Definition: Vector3.h:70
Vector3::array
vector< double > array()
Definition: Vector3.h:166
length2
double length2(vector< T > v)
Definition: Vector3.h:517
Vector3::operator/=
Vector3 operator/=(const double d)
Definition: Vector3.h:98
Vector3::length
void length(double d)
Definition: Vector3.h:223
Vector3::square_root
Vector3 square_root()
Definition: Vector3.h:229
Vector3::distance
double distance(const Vector3 &v)
Definition: Vector3.h:227
vector3_origin_to_shift
Vector3< T1 > vector3_origin_to_shift(Vector3< T1 > origin, Vector3< T2 > size)
Definition: Vector3.h:667
operator+
vector< T1 > operator+(vector< T1 > v1, vector< T2 > v2)
Definition: Vector3.h:363
Vector3::operator=
Vector3 operator=(const Vector3 &v)
Definition: Vector3.h:37
vecmin
vector< T1 > vecmin(vector< T1 > v1, vector< T2 > v2)
Definition: Vector3.h:567
Vector3::max
Type max()
Definition: Vector3.h:175
scalar
double scalar(vector< T1 > &v1, vector< T2 > &v2)
Definition: Vector3.h:611
Vector3::distance2
double distance2(const Vector3 &v)
Definition: Vector3.h:228
Vector3::operator!=
bool operator!=(const Vector3 &v)
Definition: Vector3.h:126
isfinite
bool isfinite(complex< T > &value)
Vector3::Vector3
Vector3(const Vector3 &v)
Definition: Vector3.h:32
Vector3::scalar
double scalar(const Vector3 &v) const
Definition: Vector3.h:247
Vector3::operator+
Vector3 operator+(const Vector3 &v)
Definition: Vector3.h:62
Vector3::angle
double angle(Vector3< T2 > &v)
Definition: Vector3.h:257
Vector3::operator/
Vector3 operator/(const Vector3 &v)
Definition: Vector3.h:112
length
double length(vector< T > v)
Definition: Vector3.h:528
vector3_difference_PBC
Vector3< T1 > vector3_difference_PBC(Vector3< T1 > &v1, Vector3< T1 > &v2, Vector3< T2 > &box)
Definition: Vector3.h:695
Vector3::max
Vector3 max(const double d)
Definition: Vector3.h:186
Vector3::operator-=
Vector3 operator-=(const double d)
Definition: Vector3.h:66
bfloor
double bfloor(double value, int places)
Truncates a value to a specified number of decimal places.
Definition: math_util.cpp:21
operator/=
void operator/=(vector< T1 > &v1, T2 v2)
Definition: Vector3.h:492
Vector3::operator==
bool operator==(const Vector3 &v)
Definition: Vector3.h:116
Vector3::operator==
bool operator==(const double d)
Definition: Vector3.h:121
operator+=
void operator+=(vector< T1 > &v1, vector< T2 > v2)
Definition: Vector3.h:385
operator-=
void operator-=(vector< T1 > &v1, vector< T2 > v2)
Definition: Vector3.h:431
Vector3::notfinite
bool notfinite()
Definition: Vector3.h:274
vector3_scalar_range
Vector3< Type > vector3_scalar_range(Vector3< Type > vec, double min, double max)
Definition: Vector3.h:652
Vector3::length2
double length2()
Definition: Vector3.h:221
operator-
vector< T > operator-(vector< T > v1)
Definition: Vector3.h:352
cross
vector< T1 > cross(vector< T1 > &v1, vector< T2 > &v2)
Definition: Vector3.h:622
volume
T volume(vector< T > v)
Definition: Vector3.h:545
Vector3::floor
Vector3 floor(int places)
Definition: Vector3.h:206
operator<<
ostream & operator<<(ostream &output, Vector3< Type > vec)
Definition: Vector3.h:290
Vector3::min
Vector3 min(const double d)
Definition: Vector3.h:181
absolute
vector< T > absolute(vector< T > v1)
Definition: Vector3.h:556
Vector3::operator<
bool operator<(const Vector3 &v)
Definition: Vector3.h:146
Vector3
Vector class for 3-value vectors used in 3D space. The internal variables are an array of 3 numbers.
Definition: Quaternion.h:16
Vector3::max
Vector3 max(const Vector3 &v)
Definition: Vector3.h:196
vecmax
vector< T1 > vecmax(vector< T1 > v1, vector< T2 > v2)
Definition: Vector3.h:589
bround
double bround(double value, int places)
Rounds a value to a specified number of decimal places.
Definition: math_util.cpp:39
Vector3::operator>
bool operator>(const double d)
Definition: Vector3.h:131
Vector3::min
Type min()
Definition: Vector3.h:169
Vector3::operator+=
Vector3 operator+=(const double d)
Definition: Vector3.h:50
Vector3::sum
double sum()
Definition: Vector3.h:234
Vector3::operator-=
Vector3 operator-=(const Vector3 &v)
Definition: Vector3.h:74
Vector3::Vector3
Vector3(const vector< T2 > &v)
Definition: Vector3.h:35
Vector3::volume
double volume()
Definition: Vector3.h:235
Vector3::operator/=
Vector3 operator/=(const Vector3 &v)
Definition: Vector3.h:108
Vector3::operator>=
bool operator>=(const Vector3 &v)
Definition: Vector3.h:151
Vector3::operator+=
Vector3 operator+=(const Vector3 &v)
Definition: Vector3.h:58
Vector3::operator=
Vector3 operator=(const vector< T2 > &v)
Definition: Vector3.h:42
Vector3::operator>
bool operator>(const Vector3 &v)
Definition: Vector3.h:141
tab
ostream & tab(ostream &out)
Definition: utilities.cpp:21
Vector3::within
bool within(Vector3 &v1, Vector3 &v2)
Definition: Vector3.h:279
math_util.h
Header file for general utilities.
Vector3::round
Vector3 round(int places)
Definition: Vector3.h:211
Vector3::min
Vector3 min(const Vector3 &v)
Definition: Vector3.h:191