PeriDEM 0.2.0
PeriDEM -- Peridynamics-based high-fidelity model for granular media
Loading...
Searching...
No Matches
util::Point Struct Reference

A structure to represent 3d vectors. More...

#include <point.h>

Collaboration diagram for util::Point:

Public Member Functions

 Point ()
 Constructor.
 
template<class T >
 Point (T x, T y, T z)
 Constructor.
 
template<class T >
 Point (T x[3])
 Constructor.
 
 Point (const std::vector< double > &p)
 Constructor.
 
 Point (const Point &p)
 Copy constructor.
 
std::string printStr (int nt=0, int lvl=0) const
 Returns the string containing printable information about the object.
 
void print (int nt=0, int lvl=0) const
 Prints the information about the object.
 
double length () const
 Computes the Euclidean length of the vector.
 
double lengthSq () const
 Computes the Euclidean length of the vector.
 
double dot (const Point &b) const
 Computes the dot product of this vector with another point.
 
double dist (const Point &b) const
 Computes the distance between a given point from this point.
 
Point cross (const Point &b) const
 Computes the cross product between this vector and given vector.
 
Point project (const Point &b, bool is_unit=false) const
 Computes projection of vector on this vector.
 
Point projectNormal (const Point &b, bool is_unit=false) const
 Computes projection of vector on plane with normal as this vector.
 

Data Fields

double d_x
 the x coordinate
 
double d_y
 the y coordinate
 
double d_z
 the z coordinate
 

Group operators

Pointoperator+= (const double b)
 Addition by scalar operator.
 
Pointoperator-= (const double b)
 Subtraction by scalar operator.
 
Pointoperator*= (const double b)
 Multiplication by scalar operator.
 
Pointoperator+= (const Point &b)
 Addition operator.
 
Pointoperator-= (const Point &b)
 Subtraction operator.
 
Pointoperator*= (const Point &b)
 Multiplication (pointwise/elementwise) operator.
 
Pointoperator/= (const double b)
 Division by scalar operator.
 
double & operator[] (size_t i)
 Access operator.
 
const double & operator[] (size_t i) const
 Access operator.
 
Point operator+ (Point lhs, const Point &rhs)
 Addition operator.
 
Point operator- (Point lhs, const Point &rhs)
 Subtraction operator.
 
double operator* (Point lhs, const Point rhs)
 Multiplication (dot) operator.
 
Point operator* (Point lhs, const double rhs)
 Scalar product operator.
 
Point operator+ (Point lhs, const double rhs)
 Addition by scalar operator.
 
Point operator+ (const double lhs, Point rhs)
 Addition by scalar operator.
 
Point operator- (Point lhs, const double rhs)
 Subtraction by scalar operator.
 
Point operator- (const double lhs, Point rhs)
 Subtraction by scalar operator.
 
Point operator* (const double lhs, Point rhs)
 Multiplication by scalar operator.
 
Point operator/ (Point lhs, const double rhs)
 Division by scalar operator.
 

Detailed Description

A structure to represent 3d vectors.

Definition at line 30 of file point.h.

Constructor & Destructor Documentation

◆ Point() [1/5]

util::Point::Point ( )
inline

Constructor.

Definition at line 44 of file point.h.

44: d_x(0.), d_y(0.), d_z(0.){};
double d_y
the y coordinate
Definition point.h:36
double d_z
the z coordinate
Definition point.h:39
double d_x
the x coordinate
Definition point.h:33

Referenced by projectNormal().

Here is the caller graph for this function:

◆ Point() [2/5]

template<class T >
util::Point::Point ( x,
y,
z 
)
inline

Constructor.

Parameters
xThe x coordinate
yThe y coordinate
zThe z coordinate

Definition at line 52 of file point.h.

52: d_x(x), d_y(y), d_z(z){};

◆ Point() [3/5]

template<class T >
util::Point::Point ( x[3])
inlineexplicit

Constructor.

Parameters
xThe coordinate vector

Definition at line 59 of file point.h.

59: d_x(x[0]), d_y(x[1]), d_z(x[2]){};

◆ Point() [4/5]

util::Point::Point ( const std::vector< double > &  p)
inlineexplicit

Constructor.

Parameters
pVector

Definition at line 65 of file point.h.

65 {
66
67 if (p.empty())
68 return;
69 else if (p.size() == 1)
70 d_x = p[0];
71 else if (p.size() == 2) {
72 d_x = p[0];
73 d_y = p[1];
74 } else if (p.size() == 3) {
75 d_x = p[0];
76 d_y = p[1];
77 d_z = p[2];
78 }
79 };

References d_x, d_y, and d_z.

◆ Point() [5/5]

util::Point::Point ( const Point p)
inline

Copy constructor.

Parameters
pAnother Point object

Definition at line 85 of file point.h.

85: d_x(p.d_x), d_y(p.d_y), d_z(p.d_z) {};

Member Function Documentation

◆ cross()

Point util::Point::cross ( const Point b) const
inline

Computes the cross product between this vector and given vector.

Parameters
bAnother vector
Returns
Vector Cross product

Definition at line 151 of file point.h.

151 {
152 return {-d_z * b.d_y + d_y * b.d_z,
153 d_z * b.d_x - d_x * b.d_z,
154 -d_y * b.d_x + d_x * b.d_y};
155 }

References d_x, d_y, and d_z.

Referenced by util::angle(), and util::rotate().

Here is the caller graph for this function:

◆ dist()

double util::Point::dist ( const Point b) const
inline

Computes the distance between a given point from this point.

Parameters
bAnother point
Returns
Value Distance between the two points

Definition at line 140 of file point.h.

140 {
141 return std::sqrt((d_x - b.d_x) * (d_x - b.d_x) +
142 (d_y - b.d_y) * (d_y - b.d_y) +
143 (d_z - b.d_z) * (d_z - b.d_z));
144 }

References d_x, d_y, and d_z.

Referenced by util::doubleGaussian2d(), and util::gaussian2d().

Here is the caller graph for this function:

◆ dot()

double util::Point::dot ( const Point b) const
inline

Computes the dot product of this vector with another point.

Parameters
bAnother vector
Returns
Value a dot product

Definition at line 132 of file point.h.

132 { return d_x * b.d_x + d_y * b.d_y + d_z * b
133 .d_z; }

References d_x, d_y, and d_z.

Referenced by material::RnpMaterial::getS(), project(), and projectNormal().

Here is the caller graph for this function:

◆ length()

double util::Point::length ( ) const
inline

Computes the Euclidean length of the vector.

Returns
Length Euclidean length of the vector

Definition at line 118 of file point.h.

118{ return std::sqrt(d_x * d_x + d_y * d_y + d_z * d_z); }

References d_x, d_y, and d_z.

Referenced by util::angle(), util::angle(), material::RnpMaterial::getBondForceDirection(), material::PmbMaterial::getS(), material::PdElastic::getS(), material::PdState::getS(), util::geometry::BoxPartition::isNear(), util::pointDistancePlane(), util::pointDistanceSegment(), project(), and projectNormal().

Here is the caller graph for this function:

◆ lengthSq()

double util::Point::lengthSq ( ) const
inline

Computes the Euclidean length of the vector.

Returns
Length Euclidean length of the vector

Definition at line 124 of file point.h.

124 { return d_x * d_x + d_y * d_y + d_z *
125 d_z; }

References d_x, d_y, and d_z.

Referenced by util::doLinesIntersect(), util::isPointInsideCylinder(), util::isPointInsideCylinder(), and util::pointDistanceLine().

Here is the caller graph for this function:

◆ operator*=() [1/2]

Point & util::Point::operator*= ( const double  b)
inline

Multiplication by scalar operator.

Parameters
bScalar
Returns
point Vector after multiplying b to this point

Definition at line 322 of file point.h.

322 {
323
324 d_x *= b;
325 d_y *= b;
326 d_z *= b;
327 return *this;
328 }

References d_x, d_y, and d_z.

◆ operator*=() [2/2]

Point & util::Point::operator*= ( const Point b)
inline

Multiplication (pointwise/elementwise) operator.

Parameters
bVector
Returns
point Vector after elementwise multiplication of b with this point

Definition at line 361 of file point.h.

361 {
362
363 d_x *= b.d_x;
364 d_y *= b.d_y;
365 d_z *= b.d_z;
366 return *this;
367 }

References d_x, d_y, and d_z.

◆ operator+=() [1/2]

Point & util::Point::operator+= ( const double  b)
inline

Addition by scalar operator.

Parameters
bScalar
Returns
point Vector after adding b to this point

Definition at line 296 of file point.h.

296 {
297
298 d_x += b;
299 d_y += b;
300 d_z += b;
301 return *this;
302 }

References d_x, d_y, and d_z.

◆ operator+=() [2/2]

Point & util::Point::operator+= ( const Point b)
inline

Addition operator.

Parameters
bVector to be added
Returns
point Vector after adding b to this point

Definition at line 335 of file point.h.

335 {
336
337 d_x += b.d_x;
338 d_y += b.d_y;
339 d_z += b.d_z;
340 return *this;
341 }

References d_x, d_y, and d_z.

◆ operator-=() [1/2]

Point & util::Point::operator-= ( const double  b)
inline

Subtraction by scalar operator.

Parameters
bScalar
Returns
point Vector after subtracting b from this point

Definition at line 309 of file point.h.

309 {
310
311 d_x -= b;
312 d_y -= b;
313 d_z -= b;
314 return *this;
315 }

References d_x, d_y, and d_z.

◆ operator-=() [2/2]

Point & util::Point::operator-= ( const Point b)
inline

Subtraction operator.

Parameters
bVector to subtract
Returns
point Vector after subtracting b from this point

Definition at line 348 of file point.h.

348 {
349
350 d_x -= b.d_x;
351 d_y -= b.d_y;
352 d_z -= b.d_z;
353 return *this;
354 }

References d_x, d_y, and d_z.

◆ operator/=()

Point & util::Point::operator/= ( const double  b)
inline

Division by scalar operator.

Parameters
bScalar
Returns
point Vector after dividing b elementwise from this point

Definition at line 374 of file point.h.

374 {
375
376 d_x /= b;
377 d_y /= b;
378 d_z /= b;
379 return *this;
380 }

References d_x, d_y, and d_z.

◆ operator[]() [1/2]

double & util::Point::operator[] ( size_t  i)
inline

Access operator.

Parameters
iIndex of element in vector to access
Returns
value Value of ith element in vector

Definition at line 387 of file point.h.

387 {
388
389 if (i == 0)
390 return d_x;
391 else if (i == 1)
392 return d_y;
393 else
394 return d_z;
395 }

References d_x, d_y, and d_z.

◆ operator[]() [2/2]

const double & util::Point::operator[] ( size_t  i) const
inline

Access operator.

Parameters
iIndex of element in vector to access
Returns
value Value of ith element in vector

Definition at line 398 of file point.h.

398 {
399
400 if (i == 0)
401 return d_x;
402 else if (i == 1)
403 return d_y;
404 else
405 return d_z;
406 }

References d_x, d_y, and d_z.

◆ print()

void util::Point::print ( int  nt = 0,
int  lvl = 0 
) const
inline

Prints the information about the object.

Parameters
ntNumber of tabs to append before printing
lvlInformation level (higher means more information)

Definition at line 112 of file point.h.

112{ std::cout << printStr(nt, lvl); }
std::string printStr(int nt=0, int lvl=0) const
Returns the string containing printable information about the object.
Definition point.h:94

References printStr().

Here is the call graph for this function:

◆ printStr()

std::string util::Point::printStr ( int  nt = 0,
int  lvl = 0 
) const
inline

Returns the string containing printable information about the object.

Parameters
ntNumber of tabs to append before printing
lvlInformation level (higher means more information)
Returns
string String containing printable information about the object

Definition at line 94 of file point.h.

94 {
95
96 std::string tabS = "";
97 for (int i = 0; i < nt; i++)
98 tabS += "\t";
99
100 std::ostringstream oss;
101 oss << tabS << "(" << d_x << ", " << d_y << ", " << d_z << ")";
102
103 return oss.str();
104 }

References d_x, d_y, and d_z.

Referenced by print(), fe::QuadData::printStr(), inp::ParticleDeck::printStr(), inp::PICDeck::printStr(), and particle::ParticleTransform::printStr().

Here is the caller graph for this function:

◆ project()

Point util::Point::project ( const Point b,
bool  is_unit = false 
) const
inline

Computes projection of vector on this vector.

Parameters
bAnother vector
is_unitSpecify if this is a unit vector
Returns
Vector Projection vector

Definition at line 163 of file point.h.

163 {
164 auto l_sq = (is_unit ? 1. : this->length() * this->length());
165 auto dot = this->dot(b);
166 return {dot * d_x / l_sq, dot * d_y / l_sq, dot * d_z / l_sq};
167 }
double dot(const Point &b) const
Computes the dot product of this vector with another point.
Definition point.h:132
double length() const
Computes the Euclidean length of the vector.
Definition point.h:118

References d_x, d_y, d_z, dot(), and length().

Here is the call graph for this function:

◆ projectNormal()

Point util::Point::projectNormal ( const Point b,
bool  is_unit = false 
) const
inline

Computes projection of vector on plane with normal as this vector.

Parameters
bAnother vector
is_unitSpecify if this is a unit vector
Returns
Vector Projection vector

Definition at line 175 of file point.h.

175 {
176 auto l_sq = (is_unit ? 1. : this->length() * this->length());
177 auto dot = this->dot(b);
178 return b - Point(dot * d_x / l_sq, dot * d_y / l_sq, dot * d_z / l_sq);
179 }
Point()
Constructor.
Definition point.h:44

References d_x, d_y, d_z, dot(), length(), and Point().

Here is the call graph for this function:

Friends And Related Symbol Documentation

◆ operator* [1/3]

Point operator* ( const double  lhs,
Point  rhs 
)
friend

Multiplication by scalar operator.

Parameters
lhslhs scalar
rhsrhs vector
Returns
point Vector after multiplying lhs to rhs pointwise

Definition at line 275 of file point.h.

275 {
276 rhs *= lhs;
277 return rhs;
278 }

◆ operator* [2/3]

Point operator* ( Point  lhs,
const double  rhs 
)
friend

Scalar product operator.

Parameters
lhslhs (to be modified)
rhsrhs scalar (to be multiplied to lhs)
Returns
point lhs after multiplying rhs to it

Definition at line 224 of file point.h.

224 {
225 lhs *= rhs;
226 return lhs;
227 }

◆ operator* [3/3]

double operator* ( Point  lhs,
const Point  rhs 
)
friend

Multiplication (dot) operator.

Parameters
lhslhs
rhsrhs
Returns
product Dot product of two vectors

Definition at line 214 of file point.h.

214 {
215 return lhs.d_x * rhs.d_x + lhs.d_y * rhs.d_y + lhs.d_z * rhs.d_z;
216 }

◆ operator+ [1/3]

Point operator+ ( const double  lhs,
Point  rhs 
)
friend

Addition by scalar operator.

Parameters
lhslhs scalar
rhsrhs (to be added to lhs)
Returns
point After adding lhs to rhs

Definition at line 245 of file point.h.

245 {
246 return {lhs + rhs.d_x, lhs + rhs.d_y, lhs + rhs.d_z};
247 }

◆ operator+ [2/3]

Point operator+ ( Point  lhs,
const double  rhs 
)
friend

Addition by scalar operator.

Parameters
lhslhs (to be modified)
rhsrhs (to be added to lhs)
Returns
point lhs after adding rhs to it

Definition at line 235 of file point.h.

235 {
236 return {lhs.d_x + rhs, lhs.d_y + rhs, lhs.d_z + rhs};
237 }

◆ operator+ [3/3]

Point operator+ ( Point  lhs,
const Point rhs 
)
friend

Addition operator.

Parameters
lhslhs (to be modified)
rhsrhs (to be added to lhs)
Returns
point lhs after adding rhs to it

Definition at line 192 of file point.h.

192 {
193 lhs += rhs;
194 return lhs;
195 }

◆ operator- [1/3]

Point operator- ( const double  lhs,
Point  rhs 
)
friend

Subtraction by scalar operator.

Parameters
lhslhs scalar
rhsrhs (to be subtracted from lhs)
Returns
point After subtracting rhs from lhs

Definition at line 265 of file point.h.

265 {
266 return {lhs - rhs.d_x, lhs - rhs.d_y, lhs - rhs.d_z};
267 }

◆ operator- [2/3]

Point operator- ( Point  lhs,
const double  rhs 
)
friend

Subtraction by scalar operator.

Parameters
lhslhs (to be modified)
rhsrhs (to be subtracted from lhs)
Returns
point lhs after subtracting rhs from it

Definition at line 255 of file point.h.

255 {
256 return {lhs.d_x - rhs, lhs.d_y - rhs, lhs.d_z - rhs};
257 }

◆ operator- [3/3]

Point operator- ( Point  lhs,
const Point rhs 
)
friend

Subtraction operator.

Parameters
lhslhs (to be modified)
rhsrhs (to be subtracted from lhs)
Returns
point lhs after subtracting rhs from it

Definition at line 203 of file point.h.

203 {
204 lhs -= rhs;
205 return lhs;
206 }

◆ operator/

Point operator/ ( Point  lhs,
const double  rhs 
)
friend

Division by scalar operator.

Parameters
lhslhs scalar
rhsrhs vector
Returns
point Vector after dividing lhs to rhs pointwise

Definition at line 286 of file point.h.

286 {
287 lhs /= rhs;
288 return lhs;
289 }

Field Documentation

◆ d_x

◆ d_y

◆ d_z


The documentation for this struct was generated from the following file: