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

Defines Square. More...

#include <geomObjects.h>

Inheritance diagram for geom::Square:
Collaboration diagram for geom::Square:

Public Member Functions

 Square ()
 Constructor.
 
 Square (double L, util::Point x=util::Point(), std::string description="")
 Constructor.
 
 Square (util::Point x1, util::Point x2, std::string description="")
 Constructor.
 
 Square (const Square &other)
 Copy constructor.
 
Squareoperator= (const Square &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.
 
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
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.
 
virtual bool wallContactQuery (const util::Point &x, WallContactHit &hit) const
 Closest-point / signed-gap query for analytical wall contact. Default: unsupported (returns false, clears hit).
 

Data Fields

std::vector< util::Pointd_vertices
 Vertices.
 
util::Point d_x
 Center.
 
double d_L
 Edge length of a square.
 
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 Square.

Definition at line 1017 of file geomObjects.h.

Constructor & Destructor Documentation

◆ Square() [1/4]

geom::Square::Square ( )
inline

Constructor.

Definition at line 1036 of file geomObjects.h.

1037 : GeomObject("square", ""),
1038 d_L(0.),
1039 d_r(0.),
1040 d_x(util::Point()),
1041 d_vertices({
1044 }) {
1045 };
GeomObject(std::string name="", std::string description="")
Constructor.
std::vector< util::Point > d_vertices
Vertices.
util::Point d_x
Center.
double d_L
Edge length of a square.
double d_r
Radius of bounding circle.
A structure to represent 3d vectors.
Definition point.h:30

◆ Square() [2/4]

geom::Square::Square ( double  L,
util::Point  x = util::Point(),
std::string  description = "" 
)
inline

Constructor.

Parameters
LLength along x and y-directions (Square)
xCenter point
descriptionDescription of object (e.g., further classification or any tag)

Definition at line 1054 of file geomObjects.h.

1056 : GeomObject("square", description),
1057 d_L(L),
1058 d_r(L / std::sqrt(2)),
1059 d_x(x),
1060 d_vertices({
1061 x + util::Point(-0.5 * L, -0.5 * L, 0.),
1062 x + util::Point(0.5 * L, -0.5 * L, 0.),
1063 x + util::Point(0.5 * L, 0.5 * L, 0.),
1064 x + util::Point(-0.5 * L, 0.5 * L, 0.)
1065 }) {
1066 };

◆ Square() [3/4]

geom::Square::Square ( 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 1075 of file geomObjects.h.

1076 : GeomObject("square", description),
1077 d_L((x1 - x2).length() * (1. / std::sqrt(2))),
1078 d_r((x1 - x2).length() / 2.),
1079 d_x(0.5 * (x1 + x2)) {
1080 d_vertices.push_back(x1);
1081 d_vertices.push_back(util::Point(x1.d_x + d_L, x1.d_y, x1.d_z));
1082 d_vertices.push_back(x2);
1083 d_vertices.push_back(util::Point(x2.d_x - d_L, x2.d_y, x2.d_z));
1084 };
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

References d_L, d_vertices, util::Point::d_x, util::Point::d_y, and util::Point::d_z.

◆ Square() [4/4]

geom::Square::Square ( const Square other)
inline

Copy constructor.

Parameters
otherObject to copy from

Definition at line 1090 of file geomObjects.h.

1091 : GeomObject(other.d_name, other.d_description),
1092 d_L(other.d_L),
1093 d_r(other.d_r),
1094 d_x(other.d_x),
1095 d_vertices(other.d_vertices) {
1096 d_tags = other.d_tags;
1097 }
std::vector< std::string > d_tags
Tags/attributes about the object.

References geom::GeomObject::d_tags.

Member Function Documentation

◆ boundingRadius()

double geom::Square::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 450 of file geomObjects.cpp.

450 {
451
452 return d_r;
453 }

References d_r.

◆ box() [1/2]

std::pair< util::Point, util::Point > geom::Square::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 432 of file geomObjects.cpp.

432 {
433
434 return box(0.);
435 }
std::pair< util::Point, util::Point > box() const override
Computes the bounding box of object.

References box().

Referenced by box(), doesIntersect(), isInside(), isNear(), isNear(), isOutside(), 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::Square::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 436 of file geomObjects.cpp.

437 {
438
439 return {util::Point(d_vertices[0].d_x - tol, d_vertices[0].d_y - tol,
440 0.),
441 util::Point(d_vertices[2].d_x + tol, d_vertices[2].d_y + tol,
442 0.)};
443 }

References d_vertices, and d_x.

◆ center()

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

Computes the center of object.

Returns
Point Coordinates of center

Reimplemented from geom::GeomObject.

Definition at line 428 of file geomObjects.cpp.

428 {
429 return d_x;
430 }

References d_x.

◆ doesIntersect() [1/2]

bool geom::Square::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 521 of file geomObjects.cpp.

522 {
523
524 // need to check all four corner points
525 for (auto p : geom::getCornerPoints(2, box))
526 if (this->isInside(p))
527 return true;
528
529 return false;
530 }
bool isInside(const util::Point &x) const override
Checks if point is inside this object.
std::vector< util::Point > getCornerPoints(size_t dim, const std::pair< util::Point, util::Point > &box)
Returns all corner points in the box.

References box(), geom::getCornerPoints(), and isInside().

Here is the call graph for this function:

◆ doesIntersect() [2/2]

bool geom::Square::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 489 of file geomObjects.cpp.

489 {
490
491 return isNearBoundary(x, 1.0E-8, false);
492 }
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::Square::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 445 of file geomObjects.cpp.

445 {
446
447 return 0.5*d_L;
448 }

References d_L.

◆ isInside() [1/2]

bool geom::Square::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 494 of file geomObjects.cpp.

495 {
496
497 for (auto p : geom::getCornerPoints(2, box))
498 if(!this->isInside(p))
499 return false;
500
501 return true;
502 }

References box(), geom::getCornerPoints(), and isInside().

Here is the call graph for this function:

◆ isInside() [2/2]

bool geom::Square::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 455 of file geomObjects.cpp.

455 {
457 }
bool isPointInsideRectangle(util::Point x, double x_min, double x_max, double y_min, double y_max)
Checks if point is inside a rectangle.

References d_vertices, and geom::isPointInsideRectangle().

Referenced by doesIntersect(), isInside(), isOutside(), and isOutside().

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

◆ isNear() [1/2]

bool geom::Square::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 515 of file geomObjects.cpp.

516 {
517
518 return geom::areBoxesNear(this->box(), box, tol, 2);
519 }
bool areBoxesNear(const std::pair< util::Point, util::Point > &b1, const std::pair< util::Point, util::Point > &b2, const double &tol, size_t dim)
Checks if given two boxes are within given distance from each other.

References geom::areBoxesNear(), and box().

Here is the call graph for this function:

◆ isNear() [2/2]

bool geom::Square::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 463 of file geomObjects.cpp.

464 {
465
466 // get a bigger box containing this object
467 auto bbox = box(tol);
468
469 return geom::isPointInsideBox(x, 2, bbox);
470 }
bool isPointInsideBox(util::Point x, size_t dim, const std::pair< util::Point, util::Point > &box)
Returns true if point is inside box.

References box(), and geom::isPointInsideBox().

Referenced by isNearBoundary().

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

◆ isNearBoundary()

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

cons

cons

Reimplemented from geom::GeomObject.

Definition at line 472 of file geomObjects.cpp.

474 {
475
476 // check if particle is inside the object
477 if (!isNear(x, within ? 0. : tol))
478 return false;
479
480 bool near_x_edge = util::isLess(std::abs(x.d_x - d_vertices[0].d_x), tol) or
481 util::isLess(std::abs(x.d_x - d_vertices[2].d_x), tol);
482
483 bool near_y_edge = util::isLess(std::abs(x.d_y - d_vertices[0].d_y), tol) or
484 util::isLess(std::abs(x.d_y - d_vertices[2].d_y), tol);
485
486 return near_x_edge || near_y_edge;
487 }
bool isNear(const util::Point &x, const double &tol) const override
Checks if point is within given distance of this object.
bool isLess(const double &a, const double &b)
Returns true if a < b.
Definition function.cpp:20

References d_vertices, util::Point::d_x, util::Point::d_y, 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::Square::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 504 of file geomObjects.cpp.

505 {
506
507 bool intersect = false;
508 for (auto p : geom::getCornerPoints(2, box))
509 if (!intersect)
510 intersect = this->isInside(p);
511
512 return !intersect;
513 }

References box(), geom::getCornerPoints(), and isInside().

Here is the call graph for this function:

◆ isOutside() [2/2]

bool geom::Square::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 459 of file geomObjects.cpp.

459 {
460 return !isInside(x);
461 }

References isInside().

Here is the call graph for this function:

◆ operator=()

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

Assignment operator.

Parameters
otherObject to copy from
Returns
Reference to this object

Definition at line 1104 of file geomObjects.h.

1104 {
1105 if (this != &other) {
1106 // Copy base class members
1107 d_tags = other.d_tags;
1108
1109 // Copy member variables
1110 d_L = other.d_L;
1111 d_r = other.d_r;
1112 d_x = other.d_x;
1113 d_vertices = other.d_vertices;
1114 }
1115 return *this;
1116 }

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

◆ print() [1/2]

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

Prints the information about the object.

Reimplemented from geom::GeomObject.

Definition at line 1248 of file geomObjects.h.

1248{ 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::Square::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 1241 of file geomObjects.h.

1241 {
1242 std::cout << printStr(nt, lvl);
1243 };
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::Square::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 532 of file geomObjects.cpp.

532 {
533
534 auto tabS = util::io::getTabS(nt);
535
536 std::ostringstream oss;
537
538 oss << tabS << "------- Rectangle --------" << std::endl << std::endl;
539 oss << tabS << "Name = " << d_name << std::endl;
540 oss << tabS << "Length = " << d_L << std::endl;
541 oss << tabS << "Bounding radius = " << d_r << std::endl;
542 oss << tabS << "Center = " << d_x.printStr(0, lvl) << std::endl;
543 oss << tabS << "Vertices = " << util::io::printStr(d_vertices, 0) << std::endl;
544 oss << std::endl;
545
546 if (lvl > 0)
547 oss << tabS << "Bounding box: " << util::io::printBoxStr(box(0.), nt + 1);
548
549 if (lvl == 0)
550 oss << std::endl;
551
552 return oss.str();
553 }
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
std::string printStr(const T &msg, int nt=print_default_tab)
Returns formatted string for output.
Definition io.h:53
std::string printStr(int nt=0, int lvl=0) const
Returns the string containing printable information about the object.
Definition point.h:94

References box(), d_L, geom::GeomObject::d_name, d_r, d_vertices, d_x, util::io::getTabS(), util::io::printBoxStr(), util::io::printStr(), and util::Point::printStr().

Referenced by print().

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

◆ transform()

void geom::Square::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 1118 of file geomObjects.h.

1119 {
1120 // Scale the dimensions
1121 d_L *= scale;
1122 d_r *= scale;
1123
1124 const util::Point c0 = d_x;
1125 for (auto &v : d_vertices) {
1126 v = mapSimilarity(v, c0, translation, scale, angle, axis, rotationPoint);
1127 }
1128 d_x = mapSimilarity(c0, c0, translation, scale, angle, axis, rotationPoint);
1129 }
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::Square::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 424 of file geomObjects.cpp.

424 {
425 return std::pow(d_L, 2);
426 }

References d_L.

Field Documentation

◆ d_L

double geom::Square::d_L

Edge length of a square.

Definition at line 1027 of file geomObjects.h.

Referenced by inscribedRadius(), operator=(), printStr(), Square(), transform(), and volume().

◆ d_r

double geom::Square::d_r

Radius of bounding circle.

Definition at line 1030 of file geomObjects.h.

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

◆ d_vertices

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

Vertices.

Definition at line 1021 of file geomObjects.h.

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

◆ d_x

util::Point geom::Square::d_x

Center.

Definition at line 1024 of file geomObjects.h.

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


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