PeriDEM 0.2.0
PeriDEM -- Peridynamics-based high-fidelity model for granular media
Loading...
Searching...
No Matches
util::geometry::Line Class Reference

Defines Line. More...

#include <geomObjects.h>

Inheritance diagram for util::geometry::Line:
Collaboration diagram for util::geometry::Line:

Public Member Functions

 Line ()
 Constructor.
 
 Line (util::Point x1, util::Point x2, std::string description="")
 Constructor.
 
 Line (double L, util::Point x=util::Point(), std::string description="")
 Constructor.
 
double volume () const override
 Computes the volume (area in 2d, length in 1d) of object.
 
util::Point center () const override
 Computes the center of object.
 
std::pair< util::Point, util::Pointbox () const override
 Computes the bounding box of object.
 
std::pair< util::Point, util::Pointbox (const double &tol) const override
 Computes the bounding box of object.
 
double inscribedRadius () const override
 Computes the radius of biggest circle/sphere completely within the object.
 
double boundingRadius () const override
 Computes the radius of smallest circle/sphere such that object can be fit into it.
 
std::string printStr (int nt, int lvl) const override
 Returns the string containing printable information about the object.
 
void print (int nt, int lvl) const override
 Prints the information about the object.
 
void print () const override
 Prints the information about the object.
 
Interaction with point
bool isInside (const util::Point &x) const override
 Checks if point is inside this object.
 
bool isOutside (const util::Point &x) const override
 Checks if point is outside of this object.
 
bool isNear (const util::Point &x, const double &tol) const override
 Checks if point is within given distance of this object.
 
bool isNearBoundary (const util::Point &x, const double &tol, const bool &within) const override
 cons
 
bool doesIntersect (const util::Point &x) const override
 Checks if point lies exactly on the boundary.
 
Interaction with box

TODO Implement methods

bool isInside (const std::pair< util::Point, util::Point > &box) const override
 Checks if box is completely inside.
 
bool isOutside (const std::pair< util::Point, util::Point > &box) const override
 Checks if box is outside of the object.
 
bool isNear (const std::pair< util::Point, util::Point > &box, const double &tol) const override
 Checks if box is within given distance of this object.
 
bool doesIntersect (const std::pair< util::Point, util::Point > &box) const override
 Checks if box intersects this object.
 
- Public Member Functions inherited from util::geometry::GeomObject
 GeomObject (std::string name="", std::string description="")
 Constructor.
 

Data Fields

std::vector< util::Pointd_vertices
 Vertices.
 
util::Point d_x
 Center.
 
double d_L
 Length of line.
 
double d_r
 Radius of bounding circle.
 
- Data Fields inherited from util::geometry::GeomObject
const std::string d_name
 name of object
 
const std::string d_description
 Further description of object.
 
std::vector< std::string > d_tags
 Tags/attributes about the object.
 

Detailed Description

Defines Line.

Definition at line 275 of file geomObjects.h.

Constructor & Destructor Documentation

◆ Line() [1/3]

util::geometry::Line::Line ( )
inline

Constructor.

Definition at line 281 of file geomObjects.h.

282 : GeomObject("line", ""),
283 d_r(0.),
284 d_L(0.),
285 d_x(util::Point()),
GeomObject(std::string name="", std::string description="")
Constructor.
Definition geomObjects.h:39
std::vector< util::Point > d_vertices
Vertices.
util::Point d_x
Center.
double d_L
Length of line.
double d_r
Radius of bounding circle.
A structure to represent 3d vectors.
Definition point.h:30

◆ Line() [2/3]

util::geometry::Line::Line ( util::Point  x1,
util::Point  x2,
std::string  description = "" 
)
inline

Constructor.

Parameters
x1Left-bottom corner point
x2Right-top corner point
descriptionDescription of object (e.g., further classification or any tag)

Definition at line 295 of file geomObjects.h.

296 : GeomObject("line", description),
297 d_L((x1 - x2).length()),
298 d_r(0.5 * (x1 - x2).length()),
299 d_x(0.5 * (x1 + x2)),
300 d_vertices({x1, x2}) {};

◆ Line() [3/3]

util::geometry::Line::Line ( double  L,
util::Point  x = util::Point(),
std::string  description = "" 
)
inline

Constructor.

Parameters
LLength of a line
xCenter point
descriptionDescription of object (e.g., further classification or any tag)

Definition at line 309 of file geomObjects.h.

311 : GeomObject("line", description),
312 d_L(L),
313 d_r(0.5 * L),
314 d_x(x),
315 d_vertices({x + util::Point(-0.5 * L, 0., 0.),
316 x + util::Point(0.5 * L, 0., 0.)}) {};

Member Function Documentation

◆ boundingRadius()

double util::geometry::Line::boundingRadius ( ) const
overridevirtual

Computes the radius of smallest circle/sphere such that object can be fit into it.

Returns
Radius Radius of bounding circle/sphere

Reimplemented from util::geometry::GeomObject.

Definition at line 63 of file geomObjects.cpp.

63 {
64
65 return d_r;
66 }

◆ box() [1/2]

std::pair< util::Point, util::Point > util::geometry::Line::box ( ) const
overridevirtual

Computes the bounding box of object.

Returns
Pair Left-bottom-back and right-top-front corner points of box

Reimplemented from util::geometry::GeomObject.

Definition at line 47 of file geomObjects.cpp.

47 {
48
49 return box(0.);
50 }
std::pair< util::Point, util::Point > box() const override
Computes the bounding box of object.

◆ box() [2/2]

std::pair< util::Point, util::Point > util::geometry::Line::box ( const double &  tol) const
overridevirtual

Computes the bounding box of object.

Parameters
tolTolerance/padding used in creating bounding box
Returns
Pair Left-bottom-back and right-top-front corner points of box

Reimplemented from util::geometry::GeomObject.

Definition at line 52 of file geomObjects.cpp.

53 {
54
55 return {d_vertices[0] - tol, d_vertices[1] + tol};
56 }

◆ center()

util::Point util::geometry::Line::center ( ) const
overridevirtual

Computes the center of object.

Returns
Point Coordinates of center

Reimplemented from util::geometry::GeomObject.

Definition at line 43 of file geomObjects.cpp.

43 {
44 return d_x;
45 }

◆ doesIntersect() [1/2]

bool util::geometry::Line::doesIntersect ( const std::pair< util::Point, util::Point > &  box) const
overridevirtual

Checks if box intersects this object.

Parameters
boxBox
Returns
True True if intersects

Reimplemented from util::geometry::GeomObject.

Definition at line 148 of file geomObjects.cpp.

149 {
150
151 return false;
152 }

◆ doesIntersect() [2/2]

bool util::geometry::Line::doesIntersect ( const util::Point x) const
overridevirtual

Checks if point lies exactly on the boundary.

Parameters
xPoint
Returns
True True if it lies on the boundary

Reimplemented from util::geometry::GeomObject.

Definition at line 124 of file geomObjects.cpp.

124 {
125
126 return isNearBoundary(x, 1.0E-8, false);
127 }
bool isNearBoundary(const util::Point &x, const double &tol, const bool &within) const override
cons

◆ inscribedRadius()

double util::geometry::Line::inscribedRadius ( ) const
overridevirtual

Computes the radius of biggest circle/sphere completely within the object.

Returns
Radius Radius of inscribed circle/sphere

Reimplemented from util::geometry::GeomObject.

Definition at line 58 of file geomObjects.cpp.

58 {
59
60 return d_r;
61 }

◆ isInside() [1/2]

bool util::geometry::Line::isInside ( const std::pair< util::Point, util::Point > &  box) const
overridevirtual

Checks if box is completely inside.

Parameters
boxBox
Returns
True True if box lies inside

Reimplemented from util::geometry::GeomObject.

Definition at line 129 of file geomObjects.cpp.

130 {
131
132 return false;
133 }

◆ isInside() [2/2]

bool util::geometry::Line::isInside ( const util::Point x) const
overridevirtual

Checks if point is inside this object.

Parameters
xPoint
Returns
True If point lies inside

Reimplemented from util::geometry::GeomObject.

Definition at line 68 of file geomObjects.cpp.

68 {
69
70 auto da = (d_vertices[1] - d_vertices[0]) / d_L;
71 auto db = x - d_vertices[0];
72 double dot = db * da;
73
75 return false;
76
77
78 auto dx = db - dot * da;
79
80 return util::isLess(dx.length(), 1.0E-10);
81 }
bool isGreater(const double &a, const double &b)
Returns true if a > b.
Definition function.cpp:15
bool isLess(const double &a, const double &b)
Returns true if a < b.
Definition function.cpp:20
std::vector< double > dot(const std::vector< std::vector< double > > &m, const std::vector< double > &v)
Computes the dot product between matrix and vector.
Definition matrix.cpp:38

References util::dot(), util::isGreater(), and util::isLess().

Here is the call graph for this function:

◆ isNear() [1/2]

bool util::geometry::Line::isNear ( const std::pair< util::Point, util::Point > &  box,
const double &  tol 
) const
overridevirtual

Checks if box is within given distance of this object.

Parameters
boxBox
tolTolerance used in checking the nearness
Returns
True True if box is inside within the tol distance

Reimplemented from util::geometry::GeomObject.

Definition at line 141 of file geomObjects.cpp.

143 {
144
145 return true;
146 }

◆ isNear() [2/2]

bool util::geometry::Line::isNear ( const util::Point x,
const double &  tol 
) const
overridevirtual

Checks if point is within given distance of this object.

Parameters
xPoint
tolTolerance used in checking the nearness
Returns
True True if within the tol distance

Reimplemented from util::geometry::GeomObject.

Definition at line 88 of file geomObjects.cpp.

89 {
90
91 auto da = (d_vertices[1] - d_vertices[0]) / d_L;
92 auto db = x - d_vertices[0];
93 double dot = db * da;
94
96 return false;
97
98 auto dx = db - dot * da;
99
100 return util::isLess(dx.length(), tol);
101 }

References util::dot(), util::isGreater(), and util::isLess().

Here is the call graph for this function:

◆ isNearBoundary()

bool util::geometry::Line::isNearBoundary ( const util::Point x,
const double &  tol,
const bool &  within 
) const
overridevirtual

cons

cons

Reimplemented from util::geometry::GeomObject.

Definition at line 103 of file geomObjects.cpp.

105 {
106
107 // check if particle is inside the object
108 if (!isNear(x, within ? 0. : tol))
109 return false;
110
111 auto da = (d_vertices[1] - d_vertices[0]) / d_L;
112 auto db = x - d_vertices[0];
113 double dot = db * da;
114
115 if (util::isLess(dot, 0.) or util::isGreater(dot, tol)
116 or util::isGreater(dot, d_L) or util::isLess(dot, d_L - tol))
117 return false;
118
119 auto dx = db - dot * da;
120
121 return util::isLess(dx.length(), tol);
122 }
bool isNear(const util::Point &x, const double &tol) const override
Checks if point is within given distance of this object.

References util::dot(), util::isGreater(), and util::isLess().

Here is the call graph for this function:

◆ isOutside() [1/2]

bool util::geometry::Line::isOutside ( const std::pair< util::Point, util::Point > &  box) const
overridevirtual

Checks if box is outside of the object.

Parameters
boxBox
Returns
True True if box lies outside

Reimplemented from util::geometry::GeomObject.

Definition at line 135 of file geomObjects.cpp.

136 {
137
138 return true;
139 }

◆ isOutside() [2/2]

bool util::geometry::Line::isOutside ( const util::Point x) const
overridevirtual

Checks if point is outside of this object.

Parameters
xPoint
Returns
True If point lies outside

Reimplemented from util::geometry::GeomObject.

Definition at line 83 of file geomObjects.cpp.

83 {
84
85 return !isInside(x);
86 }
bool isInside(const util::Point &x) const override
Checks if point is inside this object.

◆ print() [1/2]

void util::geometry::Line::print ( ) const
inlineoverridevirtual

Prints the information about the object.

Reimplemented from util::geometry::GeomObject.

Definition at line 436 of file geomObjects.h.

436{ print(0, 0); };
void print() const override
Prints the information about the object.

References print().

Referenced by print().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ print() [2/2]

void util::geometry::Line::print ( int  nt,
int  lvl 
) const
inlineoverridevirtual

Prints the information about the object.

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

Reimplemented from util::geometry::GeomObject.

Definition at line 429 of file geomObjects.h.

429 {
430 std::cout << printStr(nt, lvl);
431 };
std::string printStr(int nt, int lvl) const override
Returns the string containing printable information about the object.

References printStr().

Here is the call graph for this function:

◆ printStr()

std::string util::geometry::Line::printStr ( int  nt,
int  lvl 
) const
overridevirtual

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

Reimplemented from util::geometry::GeomObject.

Definition at line 154 of file geomObjects.cpp.

154 {
155
156 auto tabS = util::io::getTabS(nt);
157
158 std::ostringstream oss;
159
160 oss << tabS << "------- Line --------" << std::endl << std::endl;
161 oss << tabS << "Name = " << d_name << std::endl;
162 oss << tabS << "Length = " << d_L << std::endl;
163 oss << tabS << "Point 1 = " << d_vertices[0].printStr(0, lvl) << std::endl;
164 oss << tabS << "Point 2 = " << d_vertices[1].printStr(0, lvl) << std::endl;
165 oss << std::endl;
166
167 if (lvl > 0)
168 oss << tabS << "Bounding box: "
169 << util::io::printBoxStr(box(0.), nt + 1);
170
171 if (lvl == 0)
172 oss << std::endl;
173
174 return oss.str();
175 }
const std::string d_name
name of object
std::string printBoxStr(const std::pair< util::Point, util::Point > &box, int nt=print_default_tab)
Returns formatted string for output.
Definition io.h:168
std::string getTabS(int nt)
Returns tab spaces of given size.
Definition io.h:40

References util::io::getTabS(), and util::io::printBoxStr().

Referenced by print().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ volume()

double util::geometry::Line::volume ( ) const
overridevirtual

Computes the volume (area in 2d, length in 1d) of object.

Returns
Volume Volume of object

Reimplemented from util::geometry::GeomObject.

Definition at line 39 of file geomObjects.cpp.

39 {
40 return d_L;
41 }

Field Documentation

◆ d_L

double util::geometry::Line::d_L

Length of line.

Definition at line 445 of file geomObjects.h.

◆ d_r

double util::geometry::Line::d_r

Radius of bounding circle.

Definition at line 448 of file geomObjects.h.

◆ d_vertices

std::vector<util::Point> util::geometry::Line::d_vertices

Vertices.

Definition at line 439 of file geomObjects.h.

◆ d_x

util::Point util::geometry::Line::d_x

Center.

Definition at line 442 of file geomObjects.h.


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