Loading...
Searching...
No Matches
Vec Class Reference

A 3-vector useful for postions etc. More...

#include <Vec.h>

Public Member Functions

 Vec ()
 Dummy constructor needed by STL containers.
 Vec (double x0, double x1, double x2)
 Construct a 3-vector from three doubles.
double operator* (const Vec &v) const
 Dot product.
Vec operator* (const double &s) const
 Multiplication with scalar.
Vec operator+ (const Vec &v) const
 Add two Vecs.
Vec operator- (const Vec &v) const
 Subtract two Vecs.
Vec operator- () const
 Unary minus.
Vecoperator+= (const Vec &v)
 Add a Vec to this one.
Vecoperator-= (const Vec &v)
 Subtract a vec from this one.
Vecoperator*= (double s)
 Multiply this vec with a scalar.
Vecoperator/= (double s)
 Divide this Vec with a scalar.
double operator[] (int n) const
 const indexing
double & operator[] (int n)
 Non-const indexing.

Public Attributes

double x [3]
 The actual data.

Friends

Vec Cross (const Vec &v1, const Vec &v2)
 Cross product of two Vecs.
double Length2 (const Vec &v)
 The length of a Vec.
void Vaxpy (double a, const Vec &x, Vec &y)
 Increment y with a times x.
ostreamoperator<< (ostream &out, const Vec &v)
 Print a Vec.
istreamoperator>> (istream &in, Vec &v)
 Read a Vec.

Detailed Description

A 3-vector useful for postions etc.

The only data is the three positions (and there are no virtual functions), so the memory layout of an array of Vecs will be x0, y0, z0, x1, y1, z1, x2, ...

Almost all operations are inline for speed.

Definition at line 18 of file Vec.h.

Constructor & Destructor Documentation

◆ Vec() [1/2]

Vec::Vec ( )
inline

Dummy constructor needed by STL containers.

Definition at line 21 of file Vec.h.

21{};

◆ Vec() [2/2]

Vec::Vec ( double x0,
double x1,
double x2 )
inline

Construct a 3-vector from three doubles.

Definition at line 61 of file Vec.h.

61 {
62 x[0] = x0;
63 x[1] = x1;
64 x[2] = x2;
65}
double x[3]
The actual data.
Definition Vec.h:58

Member Function Documentation

◆ operator*() [1/2]

Vec Vec::operator* ( const double & s) const
inline

Multiplication with scalar.

Definition at line 71 of file Vec.h.

71 {
72 return Vec(s * x[0], s * x[1], s * x[2]);
73}
Vec()
Dummy constructor needed by STL containers.
Definition Vec.h:21

◆ operator*() [2/2]

double Vec::operator* ( const Vec & v) const
inline

Dot product.

Definition at line 67 of file Vec.h.

67 {
68 return x[0] * v.x[0] + x[1] * v.x[1] + x[2] * v.x[2];
69}

◆ operator*=()

Vec & Vec::operator*= ( double s)
inline

Multiply this vec with a scalar.

Definition at line 99 of file Vec.h.

99 {
100 x[0] *= s;
101 x[1] *= s;
102 x[2] *= s;
103 return *this;
104}

◆ operator+()

Vec Vec::operator+ ( const Vec & v) const
inline

Add two Vecs.

Definition at line 75 of file Vec.h.

75 {
76 return Vec(x[0] + v.x[0], x[1] + v.x[1], x[2] + v.x[2]);
77}

◆ operator+=()

Vec & Vec::operator+= ( const Vec & v)
inline

Add a Vec to this one.

Definition at line 85 of file Vec.h.

85 {
86 x[0] += v.x[0];
87 x[1] += v.x[1];
88 x[2] += v.x[2];
89 return *this;
90}

◆ operator-() [1/2]

Vec Vec::operator- ( ) const
inline

Unary minus.

Definition at line 83 of file Vec.h.

83{ return Vec(-x[0], -x[1], -x[2]); }

◆ operator-() [2/2]

Vec Vec::operator- ( const Vec & v) const
inline

Subtract two Vecs.

Definition at line 79 of file Vec.h.

79 {
80 return Vec(x[0] - v.x[0], x[1] - v.x[1], x[2] - v.x[2]);
81}

◆ operator-=()

Vec & Vec::operator-= ( const Vec & v)
inline

Subtract a vec from this one.

Definition at line 92 of file Vec.h.

92 {
93 x[0] -= v.x[0];
94 x[1] -= v.x[1];
95 x[2] -= v.x[2];
96 return *this;
97}

◆ operator/=()

Vec & Vec::operator/= ( double s)
inline

Divide this Vec with a scalar.

Definition at line 106 of file Vec.h.

106 {
107 x[0] /= s;
108 x[1] /= s;
109 x[2] /= s;
110 return *this;
111}

◆ operator[]() [1/2]

double & Vec::operator[] ( int n)
inline

Non-const indexing.

Definition at line 115 of file Vec.h.

115{ return x[n]; }

◆ operator[]() [2/2]

double Vec::operator[] ( int n) const
inline

const indexing

Definition at line 113 of file Vec.h.

113{ return x[n]; }

◆ Cross

Vec Cross ( const Vec & v1,
const Vec & v2 )
friend

Cross product of two Vecs.

Definition at line 117 of file Vec.h.

117 {
118 return Vec(v1.x[1] * v2.x[2] - v1.x[2] * v2.x[1],
119 v1.x[2] * v2.x[0] - v1.x[0] * v2.x[2],
120 v1.x[0] * v2.x[1] - v1.x[1] * v2.x[0]);
121}

◆ Length2

double Length2 ( const Vec & v)
friend

The length of a Vec.

Definition at line 129 of file Vec.h.

129 {
130 return v.x[0] * v.x[0] + v.x[1] * v.x[1] + v.x[2] * v.x[2];
131}

◆ operator<<

ostream & operator<< ( ostream & out,
const Vec & v )
friend

Print a Vec.

◆ operator>>

istream & operator>> ( istream & in,
Vec & v )
friend

Read a Vec.

◆ Vaxpy

void Vaxpy ( double a,
const Vec & x,
Vec & y )
friend

Increment y with a times x.

Definition at line 123 of file Vec.h.

123 {
124 y.x[0] += a * x.x[0];
125 y.x[1] += a * x.x[1];
126 y.x[2] += a * x.x[2];
127}

Member Data Documentation

◆ x

double Vec::x[3]

The actual data.

Definition at line 58 of file Vec.h.


The documentation for this class was generated from the following file:
  • /home/runner/work/eOn/eOn/include/eon/potentials/EMT/Asap/Vec.h