MercuryDPM  Beta
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Vec3D Class Reference

Implementation of a 3D vector (by Vitaliy). More...

#include <Vector.h>

Public Member Functions

 Vec3D ()
 constructor More...
 
 Vec3D (const Mdouble x, const Mdouble y, const Mdouble z)
 Alternative constructor, taking the three elements as arguments. More...
 
void setZero ()
 Sets all elements to zero. More...
 
bool isZero () const
 Checks if ALL elements are zero. More...
 
Vec3D operator+ (const Vec3D &a) const
 Adds another vector. More...
 
Vec3D operator- (const Vec3D &a) const
 Subtracts another vector. More...
 
Vec3D operator+ (const Mdouble a) const
 Adds a scalar. More...
 
Vec3D operator- (const Mdouble a) const
 Subtracts a scalar. More...
 
Vec3D operator* (const Mdouble a) const
 Multiplies by a scalar. More...
 
Vec3D operator/ (const Mdouble a) const
 Divides by a scalar. More...
 
Vec3Doperator+= (const Vec3D &a)
 Adds another vector. More...
 
Vec3Doperator-= (const Vec3D &a)
 Subtracts another vector. More...
 
Vec3Doperator*= (const Mdouble a)
 Multiplies by a scalar. More...
 
Vec3Doperator/= (const Mdouble a)
 Divides by a scalar. More...
 
void normalize ()
 Makes this Vec3D unit length. More...
 
void setLength (Mdouble length)
 Make this Vec3D a certain length. More...
 
Mdouble getLength () const
 Calculates the length of this Vec3D: \( \sqrt{a\cdot a} \). More...
 
Mdouble getLengthSquared () const
 Calculates the squared length of this Vec3D: \( a\cdot a \). More...
 
Mdouble getComponent (const int index) const
 Returns the requested component of this Vec3D. More...
 
void setComponent (const int index, const double val)
 Sets the requested component of this Vec3D to the requested value. More...
 
Vec3D getCylindricalCoordinates () const
 Returns the representation of this Vec3D in cylindrical coordinates. More...
 
Vec3D getFromCylindricalCoordinates () const
 Returns the representation of this Vec3D in cartesian coordinates. More...
 
bool isEqualTo (const Vec3D &other, const double tol) const
 Checks if the length this Vec3D is equal the length of other with a certain tolerance. More...
 

Static Public Member Functions

static Mdouble dot (const Vec3D &a, const Vec3D &b)
 Calculates the dot product of two Vec3D: \( a \cdot b\). More...
 
static Vec3D max (const Vec3D &a, const Vec3D &b)
 Calculates the pointwise maximum of two Vec3D. More...
 
static Vec3D min (const Vec3D &a, const Vec3D &b)
 Calculates the pointwise minimum of two Vec3D. More...
 
static Vec3D square (const Vec3D &a)
 Calculates the pointwise square of a Vec3D. More...
 
static Vec3D sqrt (const Vec3D &a)
 Calculates the pointwise square root of a Vec3D. More...
 
static Vec3D cross (const Vec3D &a, const Vec3D &b)
 Calculates the cross product of two Vec3D: \( a \times b\). More...
 
static Mdouble getDistance (const Vec3D &a, const Vec3D &b)
 Calculates the distance between two Vec3D: \( \sqrt{\left(a-b\right) \cdot \left(a-b\right)} \). More...
 
static Mdouble getDistanceSquared (const Vec3D &a, const Vec3D &b)
 Calculates the squared distance between two Vec3D: \( \left(a-b\right) \cdot \left(a-b\right) \). More...
 
static Mdouble getLength (const Vec3D &a)
 Calculates the length of a Vec3D: \( \sqrt{a\cdot a} \). More...
 
static Mdouble getLengthSquared (const Vec3D &a)
 Calculates the squared length of a Vec3D: \( a\cdot a \). More...
 
static Vec3D getUnitVector (const Vec3D &a)
 Returns a unit Vec3D based on a. More...
 

Public Attributes

Mdouble X
 the vector components More...
 
Mdouble Y
 
Mdouble Z
 

Friends

std::ostream & operator<< (std::ostream &os, const Vec3D &a)
 Adds elements to an output stream. More...
 
std::istream & operator>> (std::istream &is, Vec3D &a)
 Adds elements to an input stream. More...
 
Vec3D operator+ (const Mdouble a, const Vec3D &b)
 Adds a scalar to a vector. More...
 
Vec3D operator- (const Mdouble a, const Vec3D &b)
 Subtracts the elements of a vector from a scalar. More...
 
Vec3D operator- (const Vec3D &a)
 Subtracts a vector. More...
 
Vec3D operator* (const Mdouble a, const Vec3D &b)
 Multiplies all elements by a scalar. More...
 

Detailed Description

Implementation of a 3D vector (by Vitaliy).

Modifications 21:9:2009 - Added the inclusion guards and some include objects

Todo:
Need to generalize this to n-dimensional vectors of any type

Definition at line 45 of file Vector.h.

Constructor & Destructor Documentation

Vec3D::Vec3D ( )

constructor

Default constructor

Definition at line 31 of file Vector.cc.

References setZero().

Referenced by cross(), getCylindricalCoordinates(), getFromCylindricalCoordinates(), getUnitVector(), max(), min(), operator*(), operator+(), operator-(), operator/(), sqrt(), and square().

32 {
33  setZero();
34 }
void setZero()
Sets all elements to zero.
Definition: Vector.cc:52
Vec3D::Vec3D ( const Mdouble  x,
const Mdouble  y,
const Mdouble  z 
)

Alternative constructor, taking the three elements as arguments.

Alternative constructor, lets you define all three elements.

Parameters
[in]xthe x-component
[in]ythe y-component
[in]zthe z-component

Definition at line 42 of file Vector.cc.

References X, Y, and Z.

43 {
44  X = x;
45  Y = y;
46  Z = z;
47 }
Mdouble X
the vector components
Definition: Vector.h:52
Mdouble Y
Definition: Vector.h:52
Mdouble Z
Definition: Vector.h:52

Member Function Documentation

Vec3D Vec3D::cross ( const Vec3D a,
const Vec3D b 
)
static

Calculates the cross product of two Vec3D: \( a \times b\).

Calculates the cross product of two vectors NB: this is a STATIC function!

Parameters
[in]athe first vector
[in]bthe second vector
Returns
the cross product of the arguments

Definition at line 268 of file Vector.cc.

References Vec3D(), X, Y, and Z.

Referenced by ChuteWithHopper::addHopper(), IntersectionOfWalls::addObject(), DPMBase::computeForcesDueToWalls(), FrictionInteraction::computeFrictionForce(), DPMBase::computeInternalForces(), IntersectionOfWalls::createOpenPrism(), IntersectionOfWalls::createPrism(), BaseInteractable::getVelocityAtContact(), and AngledPeriodicBoundary::set().

269 {
270  return Vec3D(a.Y * b.Z - a.Z * b.Y, a.Z * b.X - a.X * b.Z, a.X * b.Y - a.Y * b.X);
271 }
Mdouble X
the vector components
Definition: Vector.h:52
Vec3D()
constructor
Definition: Vector.cc:31
Mdouble Y
Definition: Vector.h:52
Mdouble Z
Definition: Vector.h:52
Mdouble Vec3D::dot ( const Vec3D a,
const Vec3D b 
)
static

Calculates the dot product of two Vec3D: \( a \cdot b\).

Calculates the dot product of two vectors. NB: this is a STATIC function!

Parameters
[in]athe first vector
[in]bthe second vector
Returns
the resulting scalar

Definition at line 187 of file Vector.cc.

References X, Y, and Z.

Referenced by IntersectionOfWalls::addObject(), SlidingFrictionInteraction::computeFrictionForce(), FrictionInteraction::computeFrictionForce(), LinearPlasticViscoelasticInteraction::computeLinearPlasticViscoelasticForce(), HertzianViscoelasticInteraction::computeNormalForce(), LinearViscoelasticInteraction::computeNormalForce(), AngledPeriodicBoundary::distance(), BaseInteraction::gatherContactStatistics(), DeletionBoundary::getDistance(), MaserBoundary::getDistance(), PeriodicBoundary::getDistance(), InfiniteWall::getDistance(), AxisymmetricIntersectionOfWalls::getDistanceAndNormal(), IntersectionOfWalls::getDistanceAndNormal(), AngledPeriodicBoundary::getOpeningAngle(), InfiniteWallWithHole::getWallDistance(), FrictionInteraction::integrate(), InfiniteWallWithHole::move_time(), DeletionBoundary::set(), AngledPeriodicBoundary::set(), PeriodicBoundary::set(), InfiniteWallWithHole::set(), AngledPeriodicBoundary::shiftPosition(), AngledPeriodicBoundary::shiftPositions(), DPMBase::writeEneTimestep(), and BaseInteraction::writeToFStat().

188 {
189  return a.X * b.X + a.Y * b.Y + a.Z * b.Z;
190 }
Mdouble X
the vector components
Definition: Vector.h:52
Mdouble Y
Definition: Vector.h:52
Mdouble Z
Definition: Vector.h:52
Mdouble Vec3D::getComponent ( const int  index) const

Returns the requested component of this Vec3D.

returns the vector element belonging to the given index.

Parameters
[in]indexthe index of interest (should be 0, 1 or 2)
Returns
the value of the vector element belonging to the given index

Definition at line 323 of file Vector.cc.

References ERROR, logger, X, Y, and Z.

324  {
325  switch (index)
326  {
327  case 0:
328  return X;
329  case 1:
330  return Y;
331  case 2:
332  return Z;
333  default:
334  logger(ERROR, "[Vector::getComponent] Index = %, which is too high for a 3D vector (should be 0-2).", index);
335  return 0;
336  }
337 }
Mdouble X
the vector components
Definition: Vector.h:52
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
Mdouble Y
Definition: Vector.h:52
Mdouble Z
Definition: Vector.h:52
Vec3D Vec3D::getCylindricalCoordinates ( ) const

Returns the representation of this Vec3D in cylindrical coordinates.

Transforms the (Cartesian) vector to cylindrical coordinates

Returns
Transformed vector

Definition at line 367 of file Vector.cc.

References Vec3D(), X, Y, and Z.

368 {
369  return Vec3D(std::sqrt(X * X + Y * Y), std::atan2(Y, X), Z);
370 }
Mdouble X
the vector components
Definition: Vector.h:52
Vec3D()
constructor
Definition: Vector.cc:31
Mdouble Y
Definition: Vector.h:52
Mdouble Z
Definition: Vector.h:52
Mdouble Vec3D::getDistance ( const Vec3D a,
const Vec3D b 
)
static

Calculates the distance between two Vec3D: \( \sqrt{\left(a-b\right) \cdot \left(a-b\right)} \).

Calculates the distance (i.e. the length of the difference) between two vectors NB: this is a STATIC function!

Parameters
[in]athe first vector
[in]bthe second vector
Returns
the distance between the two arguments.

Definition at line 280 of file Vector.cc.

References getDistanceSquared().

281 {
282  return std::sqrt(getDistanceSquared(a, b));
283 }
static Mdouble getDistanceSquared(const Vec3D &a, const Vec3D &b)
Calculates the squared distance between two Vec3D: .
Definition: Vector.cc:293
Mdouble Vec3D::getDistanceSquared ( const Vec3D a,
const Vec3D b 
)
static

Calculates the squared distance between two Vec3D: \( \left(a-b\right) \cdot \left(a-b\right) \).

Calculates the square of the distance (i.e. the length of the difference) between two vectors. NB: this is a STATIC function!

Parameters
[in]athe first vector
[in]bthe second vector
Returns
the square of the distance between the two arguments.

Definition at line 293 of file Vector.cc.

References X, Y, and Z.

Referenced by DPMBase::areInContact(), DPMBase::checkParticleForInteraction(), and getDistance().

294 {
295  return ((a.X - b.X) * (a.X - b.X) + (a.Y - b.Y) * (a.Y - b.Y) + (a.Z - b.Z) * (a.Z - b.Z));
296 }
Mdouble X
the vector components
Definition: Vector.h:52
Mdouble Y
Definition: Vector.h:52
Mdouble Z
Definition: Vector.h:52
Vec3D Vec3D::getFromCylindricalCoordinates ( ) const

Returns the representation of this Vec3D in cartesian coordinates.

Transforms the (cylindrical) vector to cartesian coordinates

Returns
Transformed vector

Definition at line 376 of file Vector.cc.

References Vec3D(), X, Y, and Z.

377 {
378  return Vec3D(X * std::cos(Y), X * std::sin(Y), Z);
379 }
Mdouble X
the vector components
Definition: Vector.h:52
Vec3D()
constructor
Definition: Vector.cc:31
Mdouble Y
Definition: Vector.h:52
Mdouble Z
Definition: Vector.h:52
Mdouble Vec3D::getLength ( const Vec3D a)
static

Calculates the length of a Vec3D: \( \sqrt{a\cdot a} \).

Calculates the length of a given vector NB: this is a STATIC function!

Parameters
[in]avector to be measured.
Returns
length of the argument.

Definition at line 427 of file Vector.cc.

References getLength().

Referenced by BaseInteraction::gatherContactStatistics(), Screw::getDistanceAndNormal(), CylindricalWall::getDistanceAndNormal(), AxisymmetricIntersectionOfWalls::getDistanceAndNormal(), Coil::getDistanceAndNormal(), InfiniteWallWithHole::getDistanceAndNormal(), getLength(), SlidingFrictionInteraction::getTangentialOverlap(), Chute::setChuteAngle(), and BaseInteraction::writeToFStat().

428 {
429  return a.getLength();
430 }
static Mdouble getLength(const Vec3D &a)
Calculates the length of a Vec3D: .
Definition: Vector.cc:427
Mdouble Vec3D::getLength ( ) const

Calculates the length of this Vec3D: \( \sqrt{a\cdot a} \).

Calculates the length of this vector

Returns
the (scalar) length of this vector

Definition at line 416 of file Vector.cc.

References getLengthSquared().

Referenced by normalize(), AngledPeriodicBoundary::set(), setLength(), and InfiniteWall::setNormal().

417 {
418  return std::sqrt(getLengthSquared());
419 }
Mdouble getLengthSquared() const
Calculates the squared length of this Vec3D: .
Definition: Vector.cc:313
Mdouble Vec3D::getLengthSquared ( const Vec3D a)
static

Calculates the squared length of a Vec3D: \( a\cdot a \).

Calculates the square of the length of a given vector. NB: this is a STATIC function!

Parameters
[in]athe vector.
Returns
the square of the length of the argument.

Definition at line 304 of file Vector.cc.

References X, Y, and Z.

Referenced by ChuteWithHopper::addHopper(), SlidingFrictionInteraction::computeFrictionForce(), FrictionInteraction::computeFrictionForce(), IntersectionOfWalls::getDistanceAndNormal(), SlidingFrictionInteraction::getElasticEnergy(), FrictionInteraction::getElasticEnergy(), BaseParticle::getKineticEnergy(), getUnitVector(), and Quarternion::integrate().

305 {
306  return (a.X * a.X + a.Y * a.Y + a.Z * a.Z);
307 }
Mdouble X
the vector components
Definition: Vector.h:52
Mdouble Y
Definition: Vector.h:52
Mdouble Z
Definition: Vector.h:52
Mdouble Vec3D::getLengthSquared ( ) const

Calculates the squared length of this Vec3D: \( a\cdot a \).

Calculates the square of the length of itself

Returns
the square of the length of this vector

Definition at line 313 of file Vector.cc.

References X, Y, and Z.

Referenced by BaseParticle::getInteractionWith(), getLength(), and isEqualTo().

314 {
315  return (X * X + Y * Y + Z * Z);
316 }
Mdouble X
the vector components
Definition: Vector.h:52
Mdouble Y
Definition: Vector.h:52
Mdouble Z
Definition: Vector.h:52
Vec3D Vec3D::getUnitVector ( const Vec3D a)
static

Returns a unit Vec3D based on a.

Calculates the unit vector of a given vector (unless it is a vector with zero length; in that case it returns a 3D vector with each element equal to zero). NB: this is a STATIC function!

Parameters
[in]athe vector of interest
Returns
unit vector in the direction of the argument (unless the argument has length zero; in that case a zero-vector).

Definition at line 441 of file Vector.cc.

References getLengthSquared(), and Vec3D().

Referenced by IntersectionOfWalls::createOpenPrism(), and IntersectionOfWalls::createPrism().

442 {
443  Mdouble Length2 = a.getLengthSquared();
444  if (Length2 != 0.0)
445  return a / std::sqrt(Length2);
446  else
447  return Vec3D(0, 0, 0);
448 }
static Mdouble getLengthSquared(const Vec3D &a)
Calculates the squared length of a Vec3D: .
Definition: Vector.cc:304
Vec3D()
constructor
Definition: Vector.cc:31
double Mdouble
bool Vec3D::isEqualTo ( const Vec3D other,
const double  tol 
) const

Checks if the length this Vec3D is equal the length of other with a certain tolerance.

Checks if the length of the vector is equal to the one given in the first argument (other), with a tolerance given in the second argument (tol).

Parameters
[in]otherthe 3D vector to check against
[in]tolthe tolerance
Returns
returns TRUE if the difference between the lengths of this vector and that given in the first argument (other) is smaller than the given tolerance.

Definition at line 390 of file Vector.cc.

References getLengthSquared().

391  {
392  if ((Vec3D::getLengthSquared(*this - other)) <= tol * tol)
393  {
394  return true;
395  }
396  else
397  {
398  return false;
399  }
400 }
Mdouble getLengthSquared() const
Calculates the squared length of this Vec3D: .
Definition: Vector.cc:313
bool Vec3D::isZero ( ) const

Checks if ALL elements are zero.

Checks if ALL elements are zero

Returns
TRUE if ALL elements are zero

Definition at line 63 of file Vector.cc.

References X, Y, and Z.

64 {
65  return X == 0.0 && Y == 0.0 && Z == 0.0;
66 }
Mdouble X
the vector components
Definition: Vector.h:52
Mdouble Y
Definition: Vector.h:52
Mdouble Z
Definition: Vector.h:52
Vec3D Vec3D::max ( const Vec3D a,
const Vec3D b 
)
static

Calculates the pointwise maximum of two Vec3D.

Calculates the pointwise maximum of two vectors. NB: this is a STATIC function!

Parameters
[in]athe first vector
[in]bthe second vector
Returns
The resulting vector, in which each element is the maximum of the equivalent elements of the arguments

Definition at line 200 of file Vector.cc.

References Vec3D(), X, Y, and Z.

201 {
202  return Vec3D(std::max(a.X, b.X), std::max(a.Y, b.Y), std::max(a.Z, b.Z));
203 }
Mdouble X
the vector components
Definition: Vector.h:52
Vec3D()
constructor
Definition: Vector.cc:31
Mdouble Y
Definition: Vector.h:52
Mdouble Z
Definition: Vector.h:52
Vec3D Vec3D::min ( const Vec3D a,
const Vec3D b 
)
static

Calculates the pointwise minimum of two Vec3D.

Calculates the pointwise minimum of two vectors. NB: this is a STATIC function!

Parameters
[in]athe first vector
[in]bthe second vector
Returns
The resulting vector, in which each element is the minimum of the equivalent elements of the arguments

Definition at line 213 of file Vector.cc.

References Vec3D(), X, Y, and Z.

214 {
215  return Vec3D(std::min(a.X, b.X), std::min(a.Y, b.Y), std::min(a.Z, b.Z));
216 }
Mdouble X
the vector components
Definition: Vector.h:52
Vec3D()
constructor
Definition: Vector.cc:31
Mdouble Y
Definition: Vector.h:52
Mdouble Z
Definition: Vector.h:52
void Vec3D::normalize ( )

Makes this Vec3D unit length.

Normalises the vector, i.e. divides all elements by the vectors length (resulting in a vector in the same direction, but with unit length).

Definition at line 234 of file Vector.cc.

References getLength().

Referenced by IntersectionOfWalls::addObject(), and Quarternion::Quarternion().

235 {
236  *this /= this->getLength();
237 }
Mdouble getLength() const
Calculates the length of this Vec3D: .
Definition: Vector.cc:416
Vec3D Vec3D::operator* ( const Mdouble  a) const

Multiplies by a scalar.

Multiplies each element with a scalar

Parameters
[in]athe scalar to be multiplied with
Returns
the resulting vector

Definition at line 113 of file Vector.cc.

References Vec3D(), X, Y, and Z.

114  {
115  return Vec3D(X * a, Y * a, Z * a);
116 }
Mdouble X
the vector components
Definition: Vector.h:52
Vec3D()
constructor
Definition: Vector.cc:31
Mdouble Y
Definition: Vector.h:52
Mdouble Z
Definition: Vector.h:52
Vec3D & Vec3D::operator*= ( const Mdouble  a)

Multiplies by a scalar.

Multiplies each element by a scalar

Parameters
[in]ascalar to be multiplied by
Returns
(reference to) itself, i.e. resulting vector

Definition at line 159 of file Vector.cc.

References X, Y, and Z.

160 {
161  X *= a;
162  Y *= a;
163  Z *= a;
164  return *this;
165 }
Mdouble X
the vector components
Definition: Vector.h:52
Mdouble Y
Definition: Vector.h:52
Mdouble Z
Definition: Vector.h:52
Vec3D Vec3D::operator+ ( const Vec3D a) const

Adds another vector.

Adds vector to itself

Parameters
[in]avector to be added
Returns
resulting 3D vector

Definition at line 73 of file Vector.cc.

References Vec3D(), X, Y, and Z.

74  {
75  return Vec3D(X + a.X, Y + a.Y, Z + a.Z);
76 }
Mdouble X
the vector components
Definition: Vector.h:52
Vec3D()
constructor
Definition: Vector.cc:31
Mdouble Y
Definition: Vector.h:52
Mdouble Z
Definition: Vector.h:52
Vec3D Vec3D::operator+ ( const Mdouble  a) const

Adds a scalar.

Adds scalar to each element

Parameters
[in]ascalar to be added
Returns
resulting vector

Definition at line 93 of file Vector.cc.

References Vec3D(), X, Y, and Z.

94  {
95  return Vec3D(X + a, Y + a, Z + a);
96 }
Mdouble X
the vector components
Definition: Vector.h:52
Vec3D()
constructor
Definition: Vector.cc:31
Mdouble Y
Definition: Vector.h:52
Mdouble Z
Definition: Vector.h:52
Vec3D & Vec3D::operator+= ( const Vec3D a)

Adds another vector.

Adds a vector to itself

Parameters
[in]avector to be added
Returns
(reference to) itself, i.e. resulting vector

Definition at line 133 of file Vector.cc.

References X, Y, and Z.

134 {
135  X += a.X;
136  Y += a.Y;
137  Z += a.Z;
138  return *this;
139 }
Mdouble X
the vector components
Definition: Vector.h:52
Mdouble Y
Definition: Vector.h:52
Mdouble Z
Definition: Vector.h:52
Vec3D Vec3D::operator- ( const Vec3D a) const

Subtracts another vector.

Subtracts vector from itself

Parameters
[in]avector to be subtracted
Returns
resulting vector

Definition at line 83 of file Vector.cc.

References Vec3D(), X, Y, and Z.

84  {
85  return Vec3D(X - a.X, Y - a.Y, Z - a.Z);
86 }
Mdouble X
the vector components
Definition: Vector.h:52
Vec3D()
constructor
Definition: Vector.cc:31
Mdouble Y
Definition: Vector.h:52
Mdouble Z
Definition: Vector.h:52
Vec3D Vec3D::operator- ( const Mdouble  a) const

Subtracts a scalar.

Subtracts scalar from each element

Parameters
[in]ascalar to be subtracted
Returns
resulting vector

Definition at line 103 of file Vector.cc.

References Vec3D(), X, Y, and Z.

104  {
105  return Vec3D(X - a, Y - a, Z - a);
106 }
Mdouble X
the vector components
Definition: Vector.h:52
Vec3D()
constructor
Definition: Vector.cc:31
Mdouble Y
Definition: Vector.h:52
Mdouble Z
Definition: Vector.h:52
Vec3D & Vec3D::operator-= ( const Vec3D a)

Subtracts another vector.

Subtracts a vector from itself

Parameters
[in]avector to be subtracted
Returns
(reference to) itself, i.e. resulting vector

Definition at line 146 of file Vector.cc.

References X, Y, and Z.

147 {
148  X -= a.X;
149  Y -= a.Y;
150  Z -= a.Z;
151  return *this;
152 }
Mdouble X
the vector components
Definition: Vector.h:52
Mdouble Y
Definition: Vector.h:52
Mdouble Z
Definition: Vector.h:52
Vec3D Vec3D::operator/ ( const Mdouble  a) const

Divides by a scalar.

Divides each element by a scalar

Parameters
[in]athe scalar to be divided by
Returns
resulting vector

Definition at line 123 of file Vector.cc.

References Vec3D(), X, Y, and Z.

124  {
125  return Vec3D(X / a, Y / a, Z / a);
126 }
Mdouble X
the vector components
Definition: Vector.h:52
Vec3D()
constructor
Definition: Vector.cc:31
Mdouble Y
Definition: Vector.h:52
Mdouble Z
Definition: Vector.h:52
Vec3D & Vec3D::operator/= ( const Mdouble  a)

Divides by a scalar.

Divides each element by a scalar

Parameters
[in]ascalar to be divided by
Returns
(reference to) itself, i.e. resulting vector

Definition at line 172 of file Vector.cc.

References X, Y, and Z.

173 {
174  X /= a;
175  Y /= a;
176  Z /= a;
177  return *this;
178 }
Mdouble X
the vector components
Definition: Vector.h:52
Mdouble Y
Definition: Vector.h:52
Mdouble Z
Definition: Vector.h:52
void Vec3D::setComponent ( const int  index,
const double  val 
)

Sets the requested component of this Vec3D to the requested value.

Sets the element of the vector belonging to the first argument (index) to the value given in the second argument (val).

Parameters
[in]indexindex of element of interest,
[in]valvalue to be set

Definition at line 345 of file Vector.cc.

References ERROR, logger, X, Y, and Z.

346 {
347  switch (index)
348  {
349  case 0:
350  X = val;
351  break;
352  case 1:
353  Y = val;
354  break;
355  case 2:
356  Z = val;
357  break;
358  default:
359  logger(ERROR, "[Vector::setComponent] Index = %, which is too high for a 3D vector (should be 0-2).", index);
360  }
361 }
Mdouble X
the vector components
Definition: Vector.h:52
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
Mdouble Y
Definition: Vector.h:52
Mdouble Z
Definition: Vector.h:52
void Vec3D::setLength ( Mdouble  length)

Make this Vec3D a certain length.

Sets the length of the vector to a given scalar (while maintaining the direction).

Parameters
[in]lengththe length to be set

Definition at line 244 of file Vector.cc.

References getLength().

245 {
246  *this /= this->getLength() * length;
247 }
Mdouble getLength() const
Calculates the length of this Vec3D: .
Definition: Vector.cc:416
void Vec3D::setZero ( )

Sets all elements to zero.

Sets each element to zero.

Definition at line 52 of file Vector.cc.

References X, Y, and Z.

Referenced by BaseInteractable::BaseInteractable(), BaseInteraction::BaseInteraction(), BaseParticle::BaseParticle(), Coil::Coil(), FrictionInteraction::FrictionInteraction(), Screw::Screw(), SlidingFrictionInteraction::SlidingFrictionInteraction(), StatisticsPoint< T >::StatisticsPoint(), and Vec3D().

53 {
54  X = 0.0;
55  Y = 0.0;
56  Z = 0.0;
57 }
Mdouble X
the vector components
Definition: Vector.h:52
Mdouble Y
Definition: Vector.h:52
Mdouble Z
Definition: Vector.h:52
Vec3D Vec3D::sqrt ( const Vec3D a)
static

Calculates the pointwise square root of a Vec3D.

Calculates the pointwise square root of a given vector. NB: this is a STATIC function!

Parameters
[in]athe vector to be pointwise square rooted
Returns
the resulting vector, of which each element is the square root of the equivalent element of the argument.

Definition at line 256 of file Vector.cc.

References Vec3D(), X, Y, and Z.

257 {
258  return Vec3D(std::sqrt(a.X), std::sqrt(a.Y), std::sqrt(a.Z));
259 }
Mdouble X
the vector components
Definition: Vector.h:52
Vec3D()
constructor
Definition: Vector.cc:31
Mdouble Y
Definition: Vector.h:52
Mdouble Z
Definition: Vector.h:52
Vec3D Vec3D::square ( const Vec3D a)
static

Calculates the pointwise square of a Vec3D.

Calculates the pointwise square of the vector. NB: this is a STATIC function!

Parameters
[in]athe vector to be squared.
Returns
the resulting vector, of which each element is the square of the equivalent element of the argument.

Definition at line 225 of file Vector.cc.

References Vec3D(), X, Y, and Z.

226 {
227  return Vec3D(a.X * a.X, a.Y * a.Y, a.Z * a.Z);
228 }
Mdouble X
the vector components
Definition: Vector.h:52
Vec3D()
constructor
Definition: Vector.cc:31
Mdouble Y
Definition: Vector.h:52
Mdouble Z
Definition: Vector.h:52

Friends And Related Function Documentation

Vec3D operator* ( const Mdouble  a,
const Vec3D b 
)
friend

Multiplies all elements by a scalar.

Multiplies each element of a given vector (b) by a given scalar (a). NB: this is a global function and a friend of the Vec3D class. Gets called when a scalar multiplication of the form (Mdouble) * (Vec3D) is performed.

Parameters
[in]athe scalar
[in]bthe vector
Returns
the resulting vector

Definition at line 522 of file Vector.cc.

523 {
524  return Vec3D(b.X * a, b.Y * a, b.Z * a);
525 }
Mdouble X
the vector components
Definition: Vector.h:52
Vec3D()
constructor
Definition: Vector.cc:31
Mdouble Y
Definition: Vector.h:52
Mdouble Z
Definition: Vector.h:52
Vec3D operator+ ( const Mdouble  a,
const Vec3D b 
)
friend

Adds a scalar to a vector.

Adds a scalar to the elements of given vector NB this is a global function and a friend of the Vec3D class. Gets called when addition operation of the form (Mdouble) + (Vec3D) is performed.

Parameters
[in]athe scalar to be added
[in]bthe vector the scalar gets added to.
Returns
the resulting vector.

Definition at line 484 of file Vector.cc.

485 {
486  return Vec3D(b.X + a, b.Y + a, b.Z + a);
487 }
Mdouble X
the vector components
Definition: Vector.h:52
Vec3D()
constructor
Definition: Vector.cc:31
Mdouble Y
Definition: Vector.h:52
Mdouble Z
Definition: Vector.h:52
Vec3D operator- ( const Mdouble  a,
const Vec3D b 
)
friend

Subtracts the elements of a vector from a scalar.

Subtracts each element of a given vector from a scalar NB this is a global function and a friend of the Vec3D class. Gets called when subtraction operation of the form (Mdouble) - (Vec3D) is performed.

Parameters
[in]athe scalar
[in]bthe vector to be subtracted the scalar gets subtracted from.
Returns
the resulting vector.

Definition at line 497 of file Vector.cc.

498 {
499  return Vec3D(a - b.X, a - b.Y, a - b.Z);
500 }
Mdouble X
the vector components
Definition: Vector.h:52
Vec3D()
constructor
Definition: Vector.cc:31
Mdouble Y
Definition: Vector.h:52
Mdouble Z
Definition: Vector.h:52
Vec3D operator- ( const Vec3D a)
friend

Subtracts a vector.

Returns the negative of a given vector. NB: this is a global function and a friend of the Vec3D class. Gets called when a negation operation of the form - (Vec3D) is performed.

Parameters
[in]athe vector to be negated
Returns
the negated vector

Definition at line 509 of file Vector.cc.

510 {
511  return Vec3D(-a.X, -a.Y, -a.Z);
512 }
Mdouble X
the vector components
Definition: Vector.h:52
Vec3D()
constructor
Definition: Vector.cc:31
Mdouble Y
Definition: Vector.h:52
Mdouble Z
Definition: Vector.h:52
std::ostream& operator<< ( std::ostream &  os,
const Vec3D a 
)
friend

Adds elements to an output stream.

Adds all elements of the vector to an output stream. NB: this is a global function and a friend of the Vec3D class!

Parameters
[in]osthe output stream,
[in]aThe vector of interest
Returns
the output stream with vector elements added

Definition at line 457 of file Vector.cc.

458 {
459  os << a.X << ' ' << a.Y << ' ' << a.Z;
460  return os;
461 }
Mdouble X
the vector components
Definition: Vector.h:52
Mdouble Y
Definition: Vector.h:52
Mdouble Z
Definition: Vector.h:52
std::istream& operator>> ( std::istream &  is,
Vec3D a 
)
friend

Adds elements to an input stream.

Reads all elements of a given vector from an input stream. NB: this is a global function and a friend of the Vec3D class!

Parameters
[in,out]isthe input stream
[in,out]athe vector to be read in
Returns
the input stream from which the vector elements were read

Definition at line 470 of file Vector.cc.

471 {
472  is >> a.X >> a.Y >> a.Z;
473  return is;
474 }
Mdouble X
the vector components
Definition: Vector.h:52
Mdouble Y
Definition: Vector.h:52
Mdouble Z
Definition: Vector.h:52

Member Data Documentation

Mdouble Vec3D::X

the vector components

Definition at line 52 of file Vector.h.

Referenced by ChuteWithHopper::addHopper(), CircularPeriodicBoundary::checkBoundaryAfterParticleMoved(), Chute::cleanChute(), Chute::createBottom(), CircularPeriodicBoundary::createPeriodicParticles(), Matrix3D::cross(), cross(), dot(), Matrix3D::dyadic(), ChuteInsertionBoundary::generateParticle(), CubeInsertionBoundary::generateParticle(), getComponent(), getCylindricalCoordinates(), BaseParticle::getDisplacement2(), Screw::getDistanceAndNormal(), CylindricalWall::getDistanceAndNormal(), AxisymmetricIntersectionOfWalls::getDistanceAndNormal(), Coil::getDistanceAndNormal(), InfiniteWallWithHole::getDistanceAndNormal(), getDistanceSquared(), getFromCylindricalCoordinates(), InfiniteWallWithHole::getHoleDistance(), LeesEdwardsBoundary::getHorizontalDistance(), getLengthSquared(), Mercury2D::hGridFindOneSidedContacts(), Mercury3D::hGridFindOneSidedContacts(), Mercury2D::hGridHasParticleContacts(), Mercury2D::hGridUpdateParticle(), Mercury3D::hGridUpdateParticle(), Quarternion::integrate(), mathsFunc::isEqual(), isZero(), max(), min(), Matrix3D::operator*(), operator*(), operator*(), operator*=(), operator+(), operator+(), operator+=(), operator-(), operator-(), operator-=(), operator/(), operator/=(), operator<<(), operator>>(), Quarternion::Quarternion(), DPMBase::readNextDataFile(), ParticleHandler::readOldObject(), CircularPeriodicBoundary::rotateParticle(), MatrixSymmetric3D::selfDyadic(), AngledPeriodicBoundary::set(), setComponent(), ChuteBottom::setupInitialConditions(), setZero(), sqrt(), square(), MatrixSymmetric3D::symmetrisedDyadic(), and Vec3D().

Mdouble Vec3D::Y

Definition at line 52 of file Vector.h.

Referenced by CircularPeriodicBoundary::checkBoundaryAfterParticleMoved(), Chute::createBottom(), CircularPeriodicBoundary::createPeriodicParticles(), Matrix3D::cross(), cross(), dot(), Matrix3D::dyadic(), ChuteInsertionBoundary::generateParticle(), CubeInsertionBoundary::generateParticle(), getComponent(), getCylindricalCoordinates(), BaseParticle::getDisplacement2(), Screw::getDistanceAndNormal(), CylindricalWall::getDistanceAndNormal(), Coil::getDistanceAndNormal(), InfiniteWallWithHole::getDistanceAndNormal(), getDistanceSquared(), getFromCylindricalCoordinates(), InfiniteWallWithHole::getHoleDistance(), getLengthSquared(), LeesEdwardsBoundary::getVerticalDistance(), Mercury2D::hGridFindOneSidedContacts(), Mercury3D::hGridFindOneSidedContacts(), Mercury2D::hGridHasParticleContacts(), Mercury2D::hGridUpdateParticle(), Mercury3D::hGridUpdateParticle(), Quarternion::integrate(), mathsFunc::isEqual(), isZero(), max(), min(), Matrix3D::operator*(), operator*(), operator*(), operator*=(), operator+(), operator+(), operator+=(), operator-(), operator-(), operator-=(), operator/(), operator/=(), operator<<(), operator>>(), Quarternion::Quarternion(), DPMBase::readNextDataFile(), ParticleHandler::readOldObject(), CircularPeriodicBoundary::rotateParticle(), MatrixSymmetric3D::selfDyadic(), AngledPeriodicBoundary::set(), setComponent(), ChuteBottom::setupInitialConditions(), setZero(), sqrt(), square(), MatrixSymmetric3D::symmetrisedDyadic(), and Vec3D().


The documentation for this class was generated from the following files: