ParM  parm
A molecular dynamics library
vec.hpp
Go to the documentation of this file.
1 
13 #ifndef VEC_H
14 #define VEC_H
15 
16 #include <ostream>
17 #include <cmath>
18 using namespace std;
19 
20 typedef unsigned int uint;
21 
32 template <class T, unsigned int N>
33 class Array {
34  protected:
35  T vals[N];
36  public:
37  Array();
38  Array(const Array &rhs);
39  template <class U> Array(const Array<U, N> &rhs);
40  Array(const T locs[N]);
41  const T& get(const unsigned int n) const {return vals[n];}
42  void set(const unsigned int n, const T a){vals[n]=a;}
43  unsigned int len() const {return N;};
44 
45  T& operator[](const unsigned int i){return vals[i];};
46  const T& operator[](const unsigned int i) const {return vals[i];};
47 
48  T* begin(){return vals;};
49  T* end(){return vals + N;};
50  ~Array(){};
51 };
52 
63 template <class T, unsigned int N>
64 class NVector {
65  protected:
66  T vals[N];
67  public:
68  typedef T* iterator;
69  NVector();
70  NVector(const NVector &rhs);
71  template <class U> NVector(const NVector<U, N> &rhs);
72  NVector(const T locs[N]);
73  const T& get(const unsigned int n) const {return vals[n];}
74  void set(const unsigned int n, const T a){vals[n]=a;}
75  unsigned int len() const {return N;};
76 
77  NVector& operator+=(const NVector &rhs);
78  NVector& operator-=(const NVector &rhs);
79  template <class U> NVector& operator*=(const U rhs);
80  template <class U> NVector& operator/=(const U rhs);
81  NVector operator-() const;
82  NVector operator+(const NVector &rhs) const {return NVector(*this) += rhs;}
83  NVector operator-(const NVector &rhs) const {return NVector(*this) -= rhs;}
84  T& operator[](const unsigned int i){return vals[i];};
85  const T& operator[](const unsigned int i) const{return vals[i];};
86 
88  template <class U> NVector operator*(const U rhs) const {return NVector(*this) *= rhs;}
90  template <class U> NVector operator/(const U rhs) const {return NVector(*this) /= rhs;}
91  T* begin(){return vals;};
92  T* end(){return vals + N;};
93  ~NVector(){};
94 
95  template <class U, unsigned int M>
96  friend ostream& operator<<(ostream& out, const NVector<U, M> v);
97 };
98 
106 template <class T, unsigned int N>
107 class NumVector : public NVector<T, N> {
108  public:
109  inline NumVector() {for(unsigned int i=0; i<N; i++) NVector<T,N>::vals[i]=0;}
110  inline NumVector(const NVector<T, N> &rhs) {
111  for(unsigned int i=0; i<N; i++) NVector<T,N>::vals[i]=rhs.get(i);}
112  inline NumVector(const T rhs[N]) {
113  for(unsigned int i=0; i<N; i++) NVector<T,N>::vals[i]=rhs[i];}
114 
115  T dot (const NumVector &other) const;
116  inline T sq() const {return dot(*this);};
117  inline T mag() const {return sqrt(sq());};
118 
122  inline T distance(const NumVector &rhs) const;
131  NumVector perpto(const NumVector &other) const;
132 
133 
134  void normalize();
135  NumVector norm() const;
137 
138  template <class U, unsigned int M>
139  friend ostream& operator<<(ostream& out, const NumVector<U, M> v);
140 };
141 
151 template <class T>
152 class Vector3 : public NumVector<T, 3> {
153  public:
154  Vector3() {setx(0); sety(0); setz(0);}
155  Vector3(const T a, const T b, const T c) {setx(a); sety(b); setz(c);}
156  Vector3(const NumVector<T, 3> rhs) {setx(rhs.get(0)); sety(rhs.get(1)); setz(rhs.get(2));}
157  Vector3(const NVector<T, 3> rhs) {setx(rhs.get(0)); sety(rhs.get(1)); setz(rhs.get(2));}
158  inline const T getx() const {return NVector<T,3>::get(0);}
159  inline const T gety() const {return NVector<T,3>::get(1);}
160  inline const T getz() const {return NVector<T,3>::get(2);}
162  inline double getxd() const {return double(NVector<T,3>::get(0));}
163  inline double getyd() const {return double(NVector<T,3>::get(1));}
164  inline double getzd() const {return double(NVector<T,3>::get(2));}
165  inline void setx(const T a){NVector<T,3>::vals[0]=a;}
166  inline void sety(const T b){NVector<T,3>::vals[1]=b;}
167  inline void setz(const T c){NVector<T,3>::vals[2]=c;}
169  inline void setxd(const double a){NVector<T,3>::vals[0]=a;}
170  inline void setyd(const double b){NVector<T,3>::vals[1]=b;}
171  inline void setzd(const double c){NVector<T,3>::vals[2]=c;}
172  inline void set(const T a, const T b, const T c){
174  inline Vector3 operator-() const{
175  return Vector3(-getx(),-gety(),-getz());}
176  inline Vector3 operator+(const Vector3 &rhs) const {
177  return Vector3(getx()+rhs.getx(),gety()+rhs.gety(),getz()+rhs.getz());}
178  inline Vector3 operator-(const Vector3 &rhs) const {
179  return Vector3(getx()-rhs.getx(),gety()-rhs.gety(),getz()-rhs.getz());}
180  inline T operator*(const Vector3 &rhs) const {
181  return (getx()*rhs.getx() + gety()*rhs.gety() + getz()*rhs.getz());}
182  template <class U> inline Vector3 operator*(const U rhs) const {
183  return Vector3(getx()*rhs,gety()*rhs,getz()*rhs);}
184  template <class U> inline Vector3 operator/(const U rhs) const {
185  return Vector3(getx()/rhs,gety()/rhs,getz()/rhs);}
186  Vector3 cross (const Vector3 &rhs) const;
187  inline Vector3 norm() const {return Vector3(NumVector<T,3>::norm());};
188  inline Vector3& operator-=(const Vector3 &rhs){NVector<T,3>::operator-=(rhs); return *this;};
189  inline Vector3& operator+=(const Vector3 &rhs){NVector<T,3>::operator+=(rhs); return *this;};
190  template <class U> Vector3& operator*=(const U rhs);
191  template <class U> Vector3& operator/=(const U rhs);
192 
200  static T angle(const Vector3 &dx1, const Vector3 &dx2){
201  return acos(dx1.dot(dx2) / dx1.mag() / dx2.mag());
202  }
203 
210  static T angle(const Vector3 &x1, const Vector3 &x2, const Vector3 &x3){
211  Vector3 dx1 = x1 - x2, dx2 = x3 - x2;
212  return acos(dx1.dot(dx2) / dx1.mag() / dx2.mag());
213  }
214 
229  static T Dihedral(const Vector3 &dx1, const Vector3 &dx2, const Vector3 &dx3){
230  return atan2(dx1.dot(dx2.cross(dx3))*dx2.mag(),
231  (dx1.cross(dx2).dot(dx2.cross(dx3))));
232  }
233 
237  static T Dihedral(const Vector3 &x1, const Vector3 &x2,
238  const Vector3 &x3, const Vector3 &x4){
239  Vector3 dx1 = x2 - x1, dx2 = x3 - x2, dx3 = x4 - x3;
240  return atan2(dx1.dot(dx2.cross(dx3))*dx2.mag(),
241  (dx1.cross(dx2).dot(dx2.cross(dx3))));
242  }
243  ~Vector3(){};
244 
245  template <class U>
246  friend ostream& operator<<(ostream& out, const Vector3<U> v);
247 
248 };
249 
259 template <class T>
260 class Vector2 : public NumVector<T, 2> {
261  public:
262  Vector2() {setx(0); sety(0);}
263  Vector2(const T a, const T b) {setx(a); sety(b);}
264  Vector2(const NumVector<T, 2> rhs) {setx(rhs.get(0)); sety(rhs.get(1));}
265  Vector2(const NVector<T, 2> rhs) {setx(rhs.get(0)); sety(rhs.get(1));}
266  inline const T getx() const {return NVector<T,2>::get(0);}
267  inline const T gety() const {return NVector<T,2>::get(1);}
268  inline double getxd() const {return (double) NVector<T,2>::get(0);}
269  inline double getyd() const {return (double) NVector<T,2>::get(1);}
270  inline void setx(const T a){NVector<T,2>::vals[0]=a;}
271  inline void sety(const T b){NVector<T,2>::vals[1]=b;}
272  inline void setxd(const double a){NVector<T,2>::vals[0]= (T) a;}
273  inline void setyd(const double b){NVector<T,2>::vals[1]= (T) b;}
274  inline void set(const T a, const T b){
276  inline Vector2 operator-() const{
277  return Vector2(-getx(),-gety());}
278  inline Vector2 operator+(const Vector2 &rhs) const {
279  return Vector2(getx()+rhs.getx(),gety()+rhs.gety());}
280  inline Vector2 operator-(const Vector2 &rhs) const {
281  return Vector2(getx()-rhs.getx(),gety()-rhs.gety());}
282  inline T operator*(const Vector2 &rhs) const {
283  return (getx()*rhs.getx() + gety()*rhs.gety());}
284  template <class U> inline Vector2 operator*(const U rhs) const {
285  return Vector2(getx()*rhs,gety()*rhs);}
286  template <class U> inline Vector2 operator/(const U rhs) const {
287  return Vector2(getx()/rhs,gety()/rhs);}
289  T cross (const Vector2 &rhs) const{return getx()*rhs.gety() - rhs.getx()*gety();};
291  Vector2 cross (const T v) const{return Vector2(gety()*v, -getx()*v);};
293  Vector2 perp() const{return Vector2(gety(),-getx());};
295  inline Vector2 norm() const {return Vector2(NumVector<T,2>::norm());};
296  inline Vector2& operator-=(const Vector2 &rhs){NVector<T,2>::operator-=(rhs); return *this;};
297  inline Vector2& operator+=(const Vector2 &rhs){NVector<T,2>::operator+=(rhs); return *this;};
298  template <class U> Vector2& operator*=(const U rhs);
299  template <class U> Vector2& operator/=(const U rhs);
300 
303  Vector2 rotate(uint i);
304  inline Vector2 flip(){return Vector2(gety(), getx());};
312  if((i / 4) % 2 == 1) return flip().rotate(i%4);
313  return rotate(i%4);
314  };
315 
320  Vector2 inv = rotate(4-(i%4));
321  if((i / 4) % 2 == 0) return inv;
322  return inv.flip();
323  };
331  static T angle(const Vector2 &dx1, const Vector2 &dx2){
332  return acos(dx1.dot(dx2) / dx1.mag() / dx2.mag());
333  }
334 
341  static T angle(const Vector2 &x1, const Vector2 &x2, const Vector2 &x3){
342  Vector2 dx1 = x1 - x2, dx2 = x3 - x2;
343  return acos(dx1.dot(dx2) / dx1.mag() / dx2.mag());
344  }
345  ~Vector2(){};
346 
347  template <class U>
348  friend ostream& operator<<(ostream& out, const Vector2<U> v);
349 
350 };
351 
359 template<class C>
360 class Matrix : public NVector<Vector3<C>,3> {
361  public:
362  Vector3<C> dot(Vector3<C> v) const;
363  inline Vector3<C> operator *(Vector3<C> v) const{return dot(v);};
364  Matrix<C> SymmetricInverse() const;
365  C det() const;
366 };
367 
368 template<class C>
369 C Matrix<C>::det() const{
370  const Matrix<C> &M = *this;
371  return 2*M[0][1]*M[0][2]*M[1][2] + M[0][0]*M[1][1]*M[2][2]
372  - M[0][2]*M[0][2]*M[1][1] - M[0][0]*M[1][2]*M[1][2]
373  - M[0][1]*M[0][1]*M[2][2];
374 };
375 
376 template<class C>
378  const Matrix<C> &M = *this;
379  C d = det();
380  Matrix<C> I;
381  I[0][0] = (M[1][1]*M[2][2]-M[1][2]*M[1][2]) / d;
382  I[0][1] = (M[0][2]*M[1][2]-M[0][1]*M[2][2]) / d;
383  I[1][0] = I[0][1];
384  I[0][2] = (M[0][1]*M[1][2]-M[0][2]*M[1][1]) / d;
385  I[2][0] = I[0][2];
386  I[1][1] = (M[0][0]*M[2][2]-M[0][2]*M[0][2]) / d;
387  I[1][2] = (M[0][1]*M[0][2]-M[0][0]*M[1][2]) / d;
388  I[2][1] = I[1][2];
389  I[2][2] = (M[0][0]*M[1][1]-M[0][1]*M[0][1]) / d;
390  return I;
391 };
392 
393 template<class C>
395  return Vector3<C>(this->get(0).dot(vec),this->get(1).dot(vec),this->get(2).dot(vec));
396 }
397 
398 template <class T, unsigned int N>
400  for(unsigned int i=0; i < N; i++){
401  vals[i] = rhs.get(i);
402  }
403 }
404 
405 template <class T, unsigned int N>
407 
408 template <class T, unsigned int N>
409 Array<T, N>::Array(const T locs[N]) {
410  for(unsigned int i=0; i < N; i++) vals[i] = locs[i];
411 }
412 
413 template <class T, unsigned int N> template<class U>
415  for(unsigned int i=0; i < N; i++){
416  vals[i] = T(rhs.get(i));
417  }
418 }
419 
420 template <class T, unsigned int N>
422  for(unsigned int i=0; i < N; i++){
423  vals[i] = rhs.get(i);
424  }
425 }
426 
427 template <class T, unsigned int N>
429 
430 template <class T, unsigned int N>
431 NVector<T, N>::NVector(const T locs[N]) {
432  for(unsigned int i=0; i < N; i++) vals[i] = locs[i];
433 }
434 
435 template <class T, unsigned int N> template<class U>
437  for(unsigned int i=0; i < N; i++){
438  vals[i] = T(rhs.get(i));
439  }
440 }
441 
442 template <class T, unsigned int N>
444  NVector<T, N> newvec = NVector(*this);
445  newvec *= -1;
446  return newvec;
447 }
448 
449 template <class T, unsigned int N>
451  for(unsigned int i=0; i < N; i++){
452  vals[i] -= rhs.get(i);
453  }
454  return *this;
455 }
456 
457 template <class T, unsigned int N>
459  for(unsigned int i=0; i < N; i++){
460  vals[i] += rhs.get(i);
461  }
462  return *this;
463 }
464 
465 template <class T, unsigned int N> template <class U>
467  for(unsigned int i=0; i<N; i++){
468  vals[i] = vals[i] * rhs;
469  //set(i, T(this->get(i) * rhs));
470  }
471  return *this;
472 }
473 
474 template <class T, unsigned int N> template <class U>
476  for(unsigned int i=0; i<N; i++){
477  vals[i] = T(vals[i] / rhs);
478  }
479  return *this;
480 }
481 
482 template <class U, unsigned int M>
483 ostream& operator<< (ostream& out, const NVector<U,M> &v){
484  out << "[" << v.get(0);
485  for(unsigned int i = 1; i < M; i++)
486  out << ',' << v.get(i);
487  return out << ']';
488 }
489 
490 template <class T, unsigned int N>
491 T NumVector<T,N>::dot(const NumVector<T, N> &other) const{
492  T m = 0;
493  for(unsigned int i=0; i<N; i++){
494  m += NVector<T,N>::get(i) * other.get(i);
495  }
496  return m;
497 }
498 
499 template <class T, unsigned int N>
501  //~ NumVector<T,N> parallel = other * (this->dot(other)) / other.dot(other);
502  return (*this) - other * ((dot(other)) / other.sq());
503  //~ return other - parallel;
504 }
505 
506 template <class T, unsigned int N>
508  T m = mag();
509  *this /= m;
510 }
511 
512 template <class T, unsigned int N>
514  T m = mag();
515  return *this / m;
516 }
517 
518 
519 template <class T, unsigned int N>
520 inline T NumVector<T,N>::distance(const NumVector<T,N> &rhs) const{
521  T sum = 0;
522  for(unsigned int i=0; i<N; i++){
523  sum += pow(NVector<T,N>::get(i) - rhs.get(i), 2);
524  }
525  return sqrt(sum);
526  // return NumVector<T,N>(*this - rhs).mag();
527 }
528 
529 template<>
530 inline double NumVector<double,2>::distance(const NumVector<double,2> &rhs) const{
531  double x=get(0) - rhs.get(0), y=get(1) - rhs.get(1);
532  return hypot(x,y);
533  // return NumVector<T,N>(*this - rhs).mag();
534 }
535 
536 template<>
538  long double x=get(0) - rhs.get(0), y=get(1) - rhs.get(1);
539  return hypotl(x,y);
540  // return NumVector<T,N>(*this - rhs).mag();
541 }
542 
543 template<>
544 inline double NumVector<double,3>::distance(const NumVector<double,3> &rhs) const{
545  double x=get(0)-rhs.get(0), y=get(1)-rhs.get(1), z=get(2)-rhs.get(2);
546  return sqrt(x*x + y*y + z*z);
547  // return NumVector<T,N>(*this - rhs).mag();
548 }
549 
550 template<>
552  long double x=get(0)-rhs.get(0), y=get(1)-rhs.get(1), z=get(2)-rhs.get(2);
553  return sqrtl(x*x + y*y + z*z);
554  // return NumVector<T,N>(*this - rhs).mag();
555 }
556 
557 template<>
558 inline double NumVector<double,2>::mag() const{
559  double x=get(0), y=get(1);
560  return hypot(x,y);
561  // return NumVector<T,N>(*this - rhs).mag();
562 }
563 
564 template<>
565 inline long double NumVector<long double,2>::mag() const{
566  long double x=get(0), y=get(1);
567  return hypotl(x,y);
568  // return NumVector<T,N>(*this - rhs).mag();
569 }
570 
571 template<>
572 inline double NumVector<double,3>::mag() const{
573  double x=get(0), y=get(1), z=get(2);
574  return sqrt(x*x + y*y + z*z);
575  // return NumVector<T,N>(*this - rhs).mag();
576 }
577 
578 template<>
579 inline long double NumVector<long double,3>::mag() const{
580  long double x=get(0), y=get(1), z=get(2);
581  return sqrtl(x*x + y*y + z*z);
582  // return NumVector<T,N>(*this - rhs).mag();
583 }
584 
585 template <class U, unsigned int M>
586 ostream& operator<< (ostream& out, const NumVector<U,M> &v){
587  out << "[" << v.get(0);
588  for(int i = 1; i < M; i++)
589  out << ',' << v.get(i);
590  return out << ']';
591 }
592 
593 template <class T>
595  T newx = gety()*rhs.getz() - rhs.gety()*getz();
596  T newy = getz()*rhs.getx() - rhs.getz()*getx();
597  T newz = getx()*rhs.gety() - rhs.getx()*gety();
598  return Vector3<T>(newx, newy, newz);
599 }
600 
601 template <class T> template <class U>
603  NVector<T,3>::vals[0] *= rhs;
604  NVector<T,3>::vals[1] *= rhs;
605  NVector<T,3>::vals[2] *= rhs;
606  return *this;
607 }
608 
609 template <class T> template <class U>
611  NVector<T,3>::vals[0] /= rhs;
612  NVector<T,3>::vals[1] /= rhs;
613  NVector<T,3>::vals[2] /= rhs;
614  return *this;
615 }
616 
617 template <class U>
618 ostream& operator<< (ostream& out, const Vector3<U> v){
619  out << "{" << v.get(0);
620  for(int i = 1; i < 3; i++)
621  out << ',' << v.get(i);
622  return out << '}';
623 }
624 
625 template <class T> template <class U>
627  NVector<T,2>::vals[0] *= rhs;
628  NVector<T,2>::vals[1] *= rhs;
629  return *this;
630 }
631 
632 template <class T> template <class U>
634  NVector<T,2>::vals[0] /= rhs;
635  NVector<T,2>::vals[1] /= rhs;
636  return *this;
637 }
638 
639 template <class T>
641  if(i % 4 == 0) return (*this);
642  else if(i % 4 == 3) return Vector2(gety(), -getx());
643  else if(i % 4 == 2) return Vector2(-getx(), -gety());
644  else return Vector2(-gety(), getx());
645 }
646 
647 template <class U>
648 ostream& operator<< (ostream& out, const Vector2<U> v){
649  out << "{" << v.get(0);
650  for(int i = 1; i < 2; i++)
651  out << ',' << v.get(i);
652  return out << '}';
653 }
654 
655 #endif
void setyd(const double b)
Definition: vec.hpp:170
Vec perpto(Vec r, Vec to)
Definition: vecrand.hpp:85
Vector2(const NVector< T, 2 > rhs)
Definition: vec.hpp:265
NumVector perpto(const NumVector &other) const
Definition: vec.hpp:500
T operator*(const Vector2 &rhs) const
Definition: vec.hpp:282
Vec vec()
A one-liner for creating a Vec object, occasionally useful from within Python.
Definition: vecrand.hpp:72
C det() const
The determinant.
Definition: vec.hpp:369
NumVector(const T rhs[N])
Definition: vec.hpp:112
~Vector3()
Definition: vec.hpp:243
void setz(const T c)
Definition: vec.hpp:167
A fixed size array.
Definition: vec.hpp:33
static T angle(const Vector3 &dx1, const Vector3 &dx2)
The angle between two vectors, assuming they start at the same point (i.e. the origin).
Definition: vec.hpp:200
Vector3 & operator+=(const Vector3 &rhs)
Definition: vec.hpp:189
Vector2 flip()
Definition: vec.hpp:304
unsigned int len() const
Definition: vec.hpp:75
Vector2 & operator-=(const Vector2 &rhs)
Definition: vec.hpp:296
NVector()
Definition: vec.hpp:428
Vector3 & operator-=(const Vector3 &rhs)
Definition: vec.hpp:188
const T & get(const unsigned int n) const
Definition: vec.hpp:41
void setx(const T a)
Definition: vec.hpp:270
unsigned int uint
Definition: vec.hpp:20
Array()
Definition: vec.hpp:406
Vector2 operator/(const U rhs) const
Definition: vec.hpp:286
Vector3 operator-(const Vector3 &rhs) const
Definition: vec.hpp:178
void normalize()
Normalize in place.
Definition: vec.hpp:507
Vector3 norm() const
Definition: vec.hpp:187
T sq() const
Definition: vec.hpp:116
Vector2 operator-() const
Definition: vec.hpp:276
double getxd() const
Return x as a double. Useful with some versions of Python and long doubles.
Definition: vec.hpp:162
Vector3 operator/(const U rhs) const
Definition: vec.hpp:184
T * begin()
Definition: vec.hpp:48
Vec2 flip(Vec2 v)
Definition: vecrand.hpp:98
T distance(const NumVector &rhs) const
The magnitude of the vector, .
Definition: vec.hpp:520
Vector3 & operator/=(const U rhs)
T & operator[](const unsigned int i)
Definition: vec.hpp:45
Vector3(const NVector< T, 3 > rhs)
Definition: vec.hpp:157
An N-dimensional vector, extending addition and subtraction from the type T to the NVector class...
Definition: vec.hpp:64
T * end()
Definition: vec.hpp:49
Vector3 operator-() const
Definition: vec.hpp:174
T & operator[](const unsigned int i)
Definition: vec.hpp:84
Vector2()
Definition: vec.hpp:262
static T angle(const Vector2 &x1, const Vector2 &x2, const Vector2 &x3)
The angle between three points.
Definition: vec.hpp:341
Vector2 rotate_flip(uint i)
Rotate and flip, for .
Definition: vec.hpp:311
Vector3()
Definition: vec.hpp:154
double getyd() const
Definition: vec.hpp:163
const T gety() const
Definition: vec.hpp:267
const T getx() const
Definition: vec.hpp:266
void sety(const T b)
Definition: vec.hpp:271
void set(const unsigned int n, const T a)
Definition: vec.hpp:74
NVector operator*(const U rhs) const
Multiplication by a scalar.
Definition: vec.hpp:88
T * end()
Definition: vec.hpp:92
T mag() const
The square of the vector, .
Definition: vec.hpp:117
T operator*(const Vector3 &rhs) const
Definition: vec.hpp:180
Vector3< C > dot(Vector3< C > v) const
Definition: vec.hpp:394
double getzd() const
Definition: vec.hpp:164
NumVector()
Definition: vec.hpp:109
void setxd(const double a)
Definition: vec.hpp:272
Vector3(const NumVector< T, 3 > rhs)
Definition: vec.hpp:156
Vector2 perp() const
The vector perpendicular to this one, in the clockwise direction.
Definition: vec.hpp:293
static T Dihedral(const Vector3 &dx1, const Vector3 &dx2, const Vector3 &dx3)
The Dihedral angle between three vectors:
Definition: vec.hpp:229
~NumVector()
Definition: vec.hpp:136
NVector & operator*=(const U rhs)
Vector2 operator*(const U rhs) const
Definition: vec.hpp:284
void set(const T a, const T b, const T c)
Definition: vec.hpp:172
T dot(const NumVector &other) const
Inner product.
Definition: vec.hpp:491
const T getx() const
Definition: vec.hpp:158
Vector2(const NumVector< T, 2 > rhs)
Definition: vec.hpp:264
const T & get(const unsigned int n) const
Definition: vec.hpp:73
Vector2(const T a, const T b)
Definition: vec.hpp:263
NVector operator/(const U rhs) const
Division by a scalar.
Definition: vec.hpp:90
NumVector(const NVector< T, N > &rhs)
Definition: vec.hpp:110
const T & operator[](const unsigned int i) const
Definition: vec.hpp:46
Matrix< C > SymmetricInverse() const
The inverse of a symmetric inverse.
Definition: vec.hpp:377
Vector2 operator-(const Vector2 &rhs) const
Definition: vec.hpp:280
void setxd(const double a)
Set x with a double. Useful with some versions of Python and long doubles.
Definition: vec.hpp:169
NVector operator-(const NVector &rhs) const
Definition: vec.hpp:83
static T Dihedral(const Vector3 &x1, const Vector3 &x2, const Vector3 &x3, const Vector3 &x4)
The Dihedral angle between four points.
Definition: vec.hpp:237
A 2D physics vector, with methods for adding, subtracting, dot product, etc.
Definition: vec.hpp:260
const T gety() const
Definition: vec.hpp:159
void set(const unsigned int n, const T a)
Definition: vec.hpp:42
const T & operator[](const unsigned int i) const
Definition: vec.hpp:85
void setzd(const double c)
Definition: vec.hpp:171
const T getz() const
Definition: vec.hpp:160
~Vector2()
Definition: vec.hpp:345
Vector3 cross(const Vector3 &rhs) const
Cross product, .
Definition: vec.hpp:594
static T angle(const Vector3 &x1, const Vector3 &x2, const Vector3 &x3)
The angle between three points.
Definition: vec.hpp:210
Vector2 operator+(const Vector2 &rhs) const
Definition: vec.hpp:278
Vector3 operator*(const U rhs) const
Definition: vec.hpp:182
Vector2 norm() const
The normalized version of this vector.
Definition: vec.hpp:295
A 3x3 matrix, with methods for adding, subtracting, dot product, etc.
Definition: vec.hpp:360
void setx(const T a)
Definition: vec.hpp:165
unsigned int len() const
Definition: vec.hpp:43
~Array()
Definition: vec.hpp:50
Vector3(const T a, const T b, const T c)
Definition: vec.hpp:155
~NVector()
Definition: vec.hpp:93
T * begin()
Definition: vec.hpp:91
Vector3 operator+(const Vector3 &rhs) const
Definition: vec.hpp:176
double getyd() const
Definition: vec.hpp:269
A 3D physics vector, with methods for adding, subtracting, dot product, etc.
Definition: vec.hpp:152
void sety(const T b)
Definition: vec.hpp:166
T cross(const Vector2 &rhs) const
The 2D cross product, returning a scalar.
Definition: vec.hpp:289
Vec2 rotate(Vec2 v, uint i)
Definition: vecrand.hpp:89
NVector operator+(const NVector &rhs) const
Definition: vec.hpp:82
NumVector norm() const
Return the normalized version.
Definition: vec.hpp:513
T * iterator
Definition: vec.hpp:68
Vector3 & operator*=(const U rhs)
NVector operator-() const
Definition: vec.hpp:443
Vector2 & operator*=(const U rhs)
Vector2 cross(const T v) const
The 2D cross product with the "missing" third dimension, returning a vector.
Definition: vec.hpp:291
void setyd(const double b)
Definition: vec.hpp:273
Vec3 cross(Vec3 v1, Vec3 v2)
Definition: vecrand.hpp:80
double getxd() const
Definition: vec.hpp:268
Vector2 rotate_flip_inv(uint i)
The inverse of rotate_flip(i).
Definition: vec.hpp:319
Vector2 rotate(uint i)
Rotate by 90 degrees counter-clockwise.
Definition: vec.hpp:640
An N-dimensional physics vector, extending NVector.
Definition: vec.hpp:107
NVector & operator+=(const NVector &rhs)
Definition: vec.hpp:458
Vector2 & operator/=(const U rhs)
void set(const T a, const T b)
Definition: vec.hpp:274
NVector & operator-=(const NVector &rhs)
Definition: vec.hpp:450
NVector & operator/=(const U rhs)
Vector2 & operator+=(const Vector2 &rhs)
Definition: vec.hpp:297
static T angle(const Vector2 &dx1, const Vector2 &dx2)
The angle between two vectors, assuming they start at the same point (i.e. the origin).
Definition: vec.hpp:331