PeriDEM 0.3.0
PeriDEM -- Peridynamics-based high-fidelity model for granular media
Loading...
Searching...
No Matches
geom::Line Class Reference

Defines Line. More...

#include <geomObjects.h>

Inheritance diagram for geom::Line:
Collaboration diagram for geom::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.
 
 Line (const Line &other)
 Copy constructor.
 
Lineoperator= (const Line &other)
 Assignment operator.
 
void transform (const util::Point &translation, const double &scale, const double &angle, const util::Point &axis, const util::Point *rotationPoint) override
 Similarity about pivot \(\mathbf p\) (default: old center d_x), then rigid displacement \(\mathbf t\) = translation: \(\mathbf y = \mathbf p + s\,\mathbf R(\mathbf x-\mathbf p) + \mathbf t\). When \(\theta=0\) and \(s=1\), \(\mathbf y = \mathbf x + \mathbf t\) for every point and the center.
 
bool wallContactQuery (const util::Point &x, WallContactHit &hit) const override
 
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 geom::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 geom::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 522 of file geomObjects.h.

Constructor & Destructor Documentation

◆ Line() [1/4]

geom::Line::Line ( )
inline

Constructor.

Definition at line 540 of file geomObjects.h.

541 : GeomObject("line", ""),
542 d_r(0.),
543 d_L(0.),
544 d_x(util::Point()),
546 };
GeomObject(std::string name="", std::string description="")
Constructor.
std::vector< util::Point > d_vertices
Vertices.
double d_r
Radius of bounding circle.
double d_L
Length of line.
util::Point d_x
Center.
A structure to represent 3d vectors.
Definition point.h:30

◆ Line() [2/4]

geom::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 555 of file geomObjects.h.

556 : GeomObject("line", description),
557 d_L((x1 - x2).length()),
558 d_r(0.5 * (x1 - x2).length()),
559 d_x(0.5 * (x1 + x2)),
560 d_vertices({x1, x2}) {
561 };

◆ Line() [3/4]

geom::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 570 of file geomObjects.h.

572 : GeomObject("line", description),
573 d_L(L),
574 d_r(0.5 * L),
575 d_x(x),
576 d_vertices({
577 x + util::Point(-0.5 * L, 0., 0.),
578 x + util::Point(0.5 * L, 0., 0.)
579 }) {
580 };

◆ Line() [4/4]

geom::Line::Line ( const Line other)
inline

Copy constructor.

Parameters
otherObject to copy from

Definition at line 586 of file geomObjects.h.

587 : GeomObject(other.d_name, other.d_description),
588 d_r(other.d_r),
589 d_L(other.d_L),
590 d_x(other.d_x),
591 d_vertices(other.d_vertices) {
592 d_tags = other.d_tags;
593 }
std::vector< std::string > d_tags
Tags/attributes about the object.

References geom::GeomObject::d_tags.

Member Function Documentation

◆ boundingRadius()

double geom::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 geom::GeomObject.

Definition at line 136 of file geomObjects.cpp.

136 {
137
138 return d_r;
139 }

References d_r.

◆ box() [1/2]

std::pair< util::Point, util::Point > geom::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 geom::GeomObject.

Definition at line 120 of file geomObjects.cpp.

120 {
121
122 return box(0.);
123 }
std::pair< util::Point, util::Point > box() const override
Computes the bounding box of object.

References box().

Referenced by box(), and printStr().

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

◆ box() [2/2]

std::pair< util::Point, util::Point > geom::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 geom::GeomObject.

Definition at line 125 of file geomObjects.cpp.

126 {
127
128 return {d_vertices[0] - tol, d_vertices[1] + tol};
129 }

References d_vertices.

◆ center()

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

Computes the center of object.

Returns
Point Coordinates of center

Reimplemented from geom::GeomObject.

Definition at line 116 of file geomObjects.cpp.

116 {
117 return d_x;
118 }

References d_x.

◆ doesIntersect() [1/2]

bool geom::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 geom::GeomObject.

Definition at line 221 of file geomObjects.cpp.

222 {
223
224 return false;
225 }

◆ doesIntersect() [2/2]

bool geom::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 geom::GeomObject.

Definition at line 197 of file geomObjects.cpp.

197 {
198
199 return isNearBoundary(x, 1.0E-8, false);
200 }
bool isNearBoundary(const util::Point &x, const double &tol, const bool &within) const override
cons

References isNearBoundary().

Here is the call graph for this function:

◆ inscribedRadius()

double geom::Line::inscribedRadius ( ) const
overridevirtual

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

Returns
Radius Radius of inscribed circle/sphere

Reimplemented from geom::GeomObject.

Definition at line 131 of file geomObjects.cpp.

131 {
132
133 return d_r;
134 }

References d_r.

◆ isInside() [1/2]

bool geom::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 geom::GeomObject.

Definition at line 202 of file geomObjects.cpp.

203 {
204
205 return false;
206 }

◆ isInside() [2/2]

bool geom::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 geom::GeomObject.

Definition at line 141 of file geomObjects.cpp.

141 {
142
143 auto da = (d_vertices[1] - d_vertices[0]) / d_L;
144 auto db = x - d_vertices[0];
145 double dot = db * da;
146
147 if (util::isLess(dot, 0.) or util::isGreater(dot, d_L))
148 return false;
149
150
151 auto dx = db - dot * da;
152
153 return util::isLess(dx.length(), 1.0E-10);
154 }
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 d_L, d_vertices, util::isGreater(), and util::isLess().

Referenced by isOutside().

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

◆ isNear() [1/2]

bool geom::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 geom::GeomObject.

Definition at line 214 of file geomObjects.cpp.

216 {
217
218 return true;
219 }

◆ isNear() [2/2]

bool geom::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 geom::GeomObject.

Definition at line 161 of file geomObjects.cpp.

162 {
163
164 auto da = (d_vertices[1] - d_vertices[0]) / d_L;
165 auto db = x - d_vertices[0];
166 double dot = db * da;
167
168 if (util::isLess(dot, 0.) or util::isGreater(dot, d_L))
169 return false;
170
171 auto dx = db - dot * da;
172
173 return util::isLess(dx.length(), tol);
174 }

References d_L, d_vertices, util::isGreater(), and util::isLess().

Referenced by isNearBoundary().

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

◆ isNearBoundary()

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

cons

cons

Reimplemented from geom::GeomObject.

Definition at line 176 of file geomObjects.cpp.

178 {
179
180 // check if particle is inside the object
181 if (!isNear(x, within ? 0. : tol))
182 return false;
183
184 auto da = (d_vertices[1] - d_vertices[0]) / d_L;
185 auto db = x - d_vertices[0];
186 double dot = db * da;
187
188 if (util::isLess(dot, 0.) or util::isGreater(dot, tol)
189 or util::isGreater(dot, d_L) or util::isLess(dot, d_L - tol))
190 return false;
191
192 auto dx = db - dot * da;
193
194 return util::isLess(dx.length(), tol);
195 }
bool isNear(const util::Point &x, const double &tol) const override
Checks if point is within given distance of this object.

References d_L, d_vertices, util::isGreater(), util::isLess(), and isNear().

Referenced by doesIntersect().

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

◆ isOutside() [1/2]

bool geom::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 geom::GeomObject.

Definition at line 208 of file geomObjects.cpp.

209 {
210
211 return true;
212 }

◆ isOutside() [2/2]

bool geom::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 geom::GeomObject.

Definition at line 156 of file geomObjects.cpp.

156 {
157
158 return !isInside(x);
159 }
bool isInside(const util::Point &x) const override
Checks if point is inside this object.

References isInside().

Here is the call graph for this function:

◆ operator=()

Line & geom::Line::operator= ( const Line other)
inline

Assignment operator.

Parameters
otherObject to copy from
Returns
Reference to this object

Definition at line 600 of file geomObjects.h.

600 {
601 if (this != &other) {
602 // Copy base class members
603 d_tags = other.d_tags;
604
605 // Copy member variables
606 d_r = other.d_r;
607 d_L = other.d_L;
608 d_x = other.d_x;
609 d_vertices = other.d_vertices;
610 }
611 return *this;
612 }
double d_x
the x coordinate
Definition point.h:33

References d_L, d_r, geom::GeomObject::d_tags, d_vertices, and d_x.

◆ print() [1/2]

void geom::Line::print ( ) const
inlineoverridevirtual

Prints the information about the object.

Reimplemented from geom::GeomObject.

Definition at line 753 of file geomObjects.h.

753{ 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 geom::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 geom::GeomObject.

Definition at line 746 of file geomObjects.h.

746 {
747 std::cout << printStr(nt, lvl);
748 };
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 geom::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 geom::GeomObject.

Definition at line 227 of file geomObjects.cpp.

227 {
228
229 auto tabS = util::io::getTabS(nt);
230
231 std::ostringstream oss;
232
233 oss << tabS << "------- Line --------" << std::endl << std::endl;
234 oss << tabS << "Name = " << d_name << std::endl;
235 oss << tabS << "Length = " << d_L << std::endl;
236 oss << tabS << "Point 1 = " << d_vertices[0].printStr(0, lvl) << std::endl;
237 oss << tabS << "Point 2 = " << d_vertices[1].printStr(0, lvl) << std::endl;
238 oss << std::endl;
239
240 if (lvl > 0)
241 oss << tabS << "Bounding box: "
242 << util::io::printBoxStr(box(0.), nt + 1);
243
244 if (lvl == 0)
245 oss << std::endl;
246
247 return oss.str();
248 }
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:188
std::string getTabS(int nt)
Returns tab spaces of a given size.
Definition io.h:39

References box(), d_L, geom::GeomObject::d_name, d_vertices, 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:

◆ transform()

void geom::Line::transform ( const util::Point translation,
const double &  scale,
const double &  angle,
const util::Point axis,
const util::Point rotationPoint 
)
inlineoverridevirtual

Similarity about pivot \(\mathbf p\) (default: old center d_x), then rigid displacement \(\mathbf t\) = translation: \(\mathbf y = \mathbf p + s\,\mathbf R(\mathbf x-\mathbf p) + \mathbf t\). When \(\theta=0\) and \(s=1\), \(\mathbf y = \mathbf x + \mathbf t\) for every point and the center.

Parameters
translationRigid translation vector \(\mathbf t\) (added after rotate+scale about \(\mathbf p\))
scaleUniform scale factor
angleRotation angle (radians)
axisAxis of rotation
rotationPointIf non-null, use as \(\mathbf p\); if null, use old d_x as pivot.

Reimplemented from geom::GeomObject.

Definition at line 614 of file geomObjects.h.

615 {
616 // Scale the length
617 d_L *= scale;
618 d_r *= scale;
619
620 const util::Point c0 = d_x;
621 // Rotate and translate vertices
622 for (auto &v : d_vertices) {
623 v = mapSimilarity(v, c0, translation, scale, angle, axis, rotationPoint);
624 }
625 d_x = mapSimilarity(c0, c0, translation, scale, angle, axis, rotationPoint);
626 }
util::Point mapSimilarity(const util::Point &x, const util::Point &pivotDefault, const util::Point &t, double scale, double angle, const util::Point &axis, const util::Point *rotationPoint)
Definition geomObjects.h:55

References d_L, d_r, d_vertices, d_x, and geom::mapSimilarity().

Here is the call graph for this function:

◆ volume()

double geom::Line::volume ( ) const
overridevirtual

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

Returns
Volume Volume of object

Reimplemented from geom::GeomObject.

Definition at line 112 of file geomObjects.cpp.

112 {
113 return d_L;
114 }

References d_L.

◆ wallContactQuery()

bool geom::Line::wallContactQuery ( const util::Point x,
WallContactHit hit 
) const
overridevirtual

Finite segment wall in 2D: free space is to the left of directed vertex0 → vertex1 (outward normal = rotate tangent 90° CCW).

Reimplemented from geom::GeomObject.

Definition at line 67 of file geomObjects.cpp.

68 {
69 hit = WallContactHit();
70 if (d_vertices.size() < 2)
71 return false;
72 const util::Point &a = d_vertices[0];
73 const util::Point &b = d_vertices[1];
74 const util::Point t = b - a;
75 const double t2 = t.lengthSq();
76 if (!(t2 > 1.e-24))
77 return false;
78
79 // Outward = left of directed segment in xy (CCW rotate).
80 util::Point n(-t.d_y, t.d_x, 0.);
81 const double nl = n.length();
82 if (!(nl > 1.e-16))
83 return false;
84 n = n / nl;
85
86 double s = ((x - a) * t) / t2;
87 if (s < 0.)
88 s = 0.;
89 else if (s > 1.)
90 s = 1.;
91 hit.closest = a + s * t;
92 const util::Point dx = x - hit.closest;
93 if (s > 1.e-12 && s < 1. - 1.e-12) {
94 hit.signed_gap = dx * n;
95 hit.outward_n = n;
96 } else {
97 const double dist = dx.length();
98 if (!(dist > 1.e-16)) {
99 hit.signed_gap = 0.;
100 hit.outward_n = n;
101 } else {
102 hit.outward_n = dx / dist;
103 hit.signed_gap = (hit.outward_n * n >= 0.) ? dist : -dist;
104 if (hit.outward_n * n < 0.)
105 hit.outward_n = n;
106 }
107 }
108 hit.active = true;
109 return true;
110 }
double d_y
the y coordinate
Definition point.h:36
double length() const
Computes the Euclidean length of the vector.
Definition point.h:124
double lengthSq() const
Computes the Euclidean length of the vector.
Definition point.h:130

References geom::WallContactHit::active, geom::WallContactHit::closest, d_vertices, util::Point::d_x, util::Point::d_y, util::Point::length(), util::Point::lengthSq(), geom::WallContactHit::outward_n, and geom::WallContactHit::signed_gap.

Here is the call graph for this function:

Field Documentation

◆ d_L

double geom::Line::d_L

Length of line.

Definition at line 531 of file geomObjects.h.

Referenced by isInside(), isNear(), isNearBoundary(), operator=(), printStr(), transform(), and volume().

◆ d_r

double geom::Line::d_r

Radius of bounding circle.

Definition at line 534 of file geomObjects.h.

Referenced by boundingRadius(), inscribedRadius(), operator=(), and transform().

◆ d_vertices

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

Vertices.

Definition at line 525 of file geomObjects.h.

Referenced by box(), isInside(), isNear(), isNearBoundary(), operator=(), printStr(), transform(), and wallContactQuery().

◆ d_x

util::Point geom::Line::d_x

Center.

Definition at line 528 of file geomObjects.h.

Referenced by center(), operator=(), and transform().


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