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

Defines Rectangle. More...

#include <geomObjects.h>

Inheritance diagram for util::geometry::Rectangle:
Collaboration diagram for util::geometry::Rectangle:

Public Member Functions

 Rectangle ()
 Constructor.
 
 Rectangle (double Lx, double Ly, util::Point x=util::Point(), std::string description="")
 Constructor.
 
 Rectangle (util::Point x1, util::Point x2, 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
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_Lx
 Edge length of a rectangle in x-direction.
 
double d_Ly
 Edge length of a rectangle in y-direction.
 
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 Rectangle.

Definition at line 827 of file geomObjects.h.

Constructor & Destructor Documentation

◆ Rectangle() [1/3]

util::geometry::Rectangle::Rectangle ( )
inline

Constructor.

Definition at line 833 of file geomObjects.h.

834 : GeomObject("rectangle", ""),
835 d_Lx(0.),
836 d_Ly(0.),
837 d_r(0.),
838 d_x(util::Point()),
840 util::Point(), util::Point()}) {};
GeomObject(std::string name="", std::string description="")
Constructor.
Definition geomObjects.h:39
util::Point d_x
Center.
double d_r
Radius of bounding circle.
double d_Ly
Edge length of a rectangle in y-direction.
double d_Lx
Edge length of a rectangle in x-direction.
std::vector< util::Point > d_vertices
Vertices.
A structure to represent 3d vectors.
Definition point.h:30

◆ Rectangle() [2/3]

util::geometry::Rectangle::Rectangle ( double  Lx,
double  Ly,
util::Point  x = util::Point(),
std::string  description = "" 
)
inline

Constructor.

Parameters
LxLength along x-direction
LyLength along y-direction
xCenter point
descriptionDescription of object (e.g., further classification or any tag)

Definition at line 850 of file geomObjects.h.

852 : GeomObject("rectangle", description),
853 d_Lx(Lx),
854 d_Ly(Ly),
855 d_r(0.5 * std::sqrt(std::pow(Lx, 2) + std::pow(Ly, 2))),
856 d_x(x) {
857
858 d_vertices.push_back(
859 x + util::Point(-0.5 * d_Lx, -0.5 * d_Ly, 0.));
860 d_vertices.push_back(
861 x + util::Point(0.5 * d_Lx, -0.5 * d_Ly, 0.));
862 d_vertices.push_back(x + util::Point(0.5 * d_Lx, 0.5 * d_Ly, 0.));
863 d_vertices.push_back(
864 x + util::Point(-0.5 * d_Lx, 0.5 * d_Ly, 0.));
865 };

References d_Lx, d_Ly, and d_vertices.

◆ Rectangle() [3/3]

util::geometry::Rectangle::Rectangle ( 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 874 of file geomObjects.h.

876 : GeomObject("rectangle", description),
877 d_Lx(x2.d_x - x1.d_x),
878 d_Ly(x2.d_y - x1.d_y),
879 d_r(0.5 *
880 std::sqrt(std::pow(d_Lx, 2) + std::pow(d_Ly, 2))),
881 d_x(0.5 * (x1 + x2)) {
882
883 d_vertices.push_back(x1);
884 d_vertices.push_back(util::Point(x1.d_x + d_Lx, x1.d_y, x1.d_z));
885 d_vertices.push_back(x2);
886 d_vertices.push_back(util::Point(x2.d_x - d_Lx, x2.d_y, x2.d_z));
887 };
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_Lx, d_vertices, util::Point::d_x, util::Point::d_y, and util::Point::d_z.

Member Function Documentation

◆ boundingRadius()

double util::geometry::Rectangle::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 508 of file geomObjects.cpp.

508 {
509
510 return d_r;
511 }

◆ box() [1/2]

std::pair< util::Point, util::Point > util::geometry::Rectangle::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 489 of file geomObjects.cpp.

489 {
490
491 return box(0.);
492 }
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::Rectangle::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 494 of file geomObjects.cpp.

495 {
496
497 return {util::Point(d_vertices[0].d_x - tol, d_vertices[0].d_y - tol,
498 0.),
499 util::Point(d_vertices[2].d_x + tol, d_vertices[2].d_y + tol,
500 0.)};
501 }

◆ center()

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

Computes the center of object.

Returns
Point Coordinates of center

Reimplemented from util::geometry::GeomObject.

Definition at line 485 of file geomObjects.cpp.

485 {
486 return d_x;
487 }

◆ doesIntersect() [1/2]

bool util::geometry::Rectangle::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 580 of file geomObjects.cpp.

581 {
582
583 // need to check all four corner points
584 for (auto p: util::getCornerPoints(2, box))
585 if (this->isInside(p))
586 return true;
587
588 return false;
589 }
bool isInside(const util::Point &x) const override
Checks if point is inside this object.
Collection of methods useful in simulation.
std::vector< util::Point > getCornerPoints(size_t dim, const std::pair< util::Point, util::Point > &box)
Returns all corner points in the box.
Definition geom.cpp:14

References util::getCornerPoints().

Here is the call graph for this function:

◆ doesIntersect() [2/2]

bool util::geometry::Rectangle::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 547 of file geomObjects.cpp.

547 {
548
549 return isNearBoundary(x, 1.0E-8, false);
550 }
bool isNearBoundary(const util::Point &x, const double &tol, const bool &within) const override
cons

◆ inscribedRadius()

double util::geometry::Rectangle::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 503 of file geomObjects.cpp.

503 {
504
505 return util::isLess(d_Lx, d_Ly) ? d_Lx : d_Ly;
506 }
bool isLess(const double &a, const double &b)
Returns true if a < b.
Definition function.cpp:20

References util::isLess().

Here is the call graph for this function:

◆ isInside() [1/2]

bool util::geometry::Rectangle::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 552 of file geomObjects.cpp.

553 {
554
555 for (auto p: util::getCornerPoints(2, box))
556 if (!this->isInside(p))
557 return false;
558
559 return true;
560 }

References util::getCornerPoints().

Here is the call graph for this function:

◆ isInside() [2/2]

bool util::geometry::Rectangle::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 513 of file geomObjects.cpp.

513 {
515 }
bool isPointInsideRectangle(util::Point x, double x_min, double x_max, double y_min, double y_max)
Checks if point is inside a rectangle.
Definition geom.cpp:231

References util::isPointInsideRectangle().

Here is the call graph for this function:

◆ isNear() [1/2]

bool util::geometry::Rectangle::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 573 of file geomObjects.cpp.

575 {
576
577 return util::areBoxesNear(this->box(), box, tol, 2);
578 }
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.
Definition geom.cpp:109

References util::areBoxesNear().

Here is the call graph for this function:

◆ isNear() [2/2]

bool util::geometry::Rectangle::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 521 of file geomObjects.cpp.

522 {
523
524 // get a bigger box containing this object
525 auto bbox = box(tol);
526
527 return util::isPointInsideBox(x, 2, bbox);
528 }
bool isPointInsideBox(util::Point x, size_t dim, const std::pair< util::Point, util::Point > &box)
Returns true if point is inside box.
Definition geom.cpp:159

References util::isPointInsideBox().

Here is the call graph for this function:

◆ isNearBoundary()

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

cons

cons

Reimplemented from util::geometry::GeomObject.

Definition at line 530 of file geomObjects.cpp.

532 {
533
534 // check if particle is inside the object
535 if (!isNear(x, within ? 0. : tol))
536 return false;
537
538 bool near_x_edge = util::isLess(std::abs(x.d_x - d_vertices[0].d_x), tol) or
539 util::isLess(std::abs(x.d_x - d_vertices[2].d_x), tol);
540
541 bool near_y_edge = util::isLess(std::abs(x.d_y - d_vertices[0].d_y), tol) or
542 util::isLess(std::abs(x.d_y - d_vertices[2].d_y), tol);
543
544 return near_x_edge || near_y_edge;
545 }
bool isNear(const util::Point &x, const double &tol) const override
Checks if point is within given distance of this object.

References util::Point::d_x, util::Point::d_y, and util::isLess().

Here is the call graph for this function:

◆ isOutside() [1/2]

bool util::geometry::Rectangle::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 562 of file geomObjects.cpp.

563 {
564
565 bool intersect = false;
566 for (auto p: util::getCornerPoints(2, box))
567 if (!intersect)
568 intersect = this->isInside(p);
569
570 return !intersect;
571 }

References util::getCornerPoints().

Here is the call graph for this function:

◆ isOutside() [2/2]

bool util::geometry::Rectangle::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 517 of file geomObjects.cpp.

517 {
518 return !isInside(x);
519 }

◆ print() [1/2]

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

Prints the information about the object.

Reimplemented from util::geometry::GeomObject.

Definition at line 1006 of file geomObjects.h.

1006{ 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::Rectangle::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 999 of file geomObjects.h.

999 {
1000 std::cout << printStr(nt, lvl);
1001 };
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::Rectangle::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 591 of file geomObjects.cpp.

591 {
592
593 auto tabS = util::io::getTabS(nt);
594
595 std::ostringstream oss;
596
597 oss << tabS << "------- Rectangle --------" << std::endl << std::endl;
598 oss << tabS << "Name = " << d_name << std::endl;
599 oss << tabS << "Lengths (Lx, Ly) = (" << d_Lx << ", " << d_Ly << ")" << std::endl;
600 oss << tabS << "Bounding circle radius = " << d_r << std::endl;
601 oss << tabS << "Vertices = " << util::io::printStr(d_vertices, 0) << std::endl;
602 oss << std::endl;
603
604 if (lvl > 0)
605 oss << tabS << "Bounding box: "
606 << util::io::printBoxStr(box(0.), nt + 1);
607
608 if (lvl == 0)
609 oss << std::endl;
610
611 return oss.str();
612 }
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
std::string printStr(const T &msg, int nt=print_default_tab)
Returns formatted string for output.
Definition io.h:54

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

Referenced by print().

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

◆ volume()

double util::geometry::Rectangle::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 481 of file geomObjects.cpp.

481 {
482 return d_Lx * d_Ly;
483 }

Field Documentation

◆ d_Lx

double util::geometry::Rectangle::d_Lx

Edge length of a rectangle in x-direction.

Definition at line 1015 of file geomObjects.h.

Referenced by Rectangle(), and Rectangle().

◆ d_Ly

double util::geometry::Rectangle::d_Ly

Edge length of a rectangle in y-direction.

Definition at line 1018 of file geomObjects.h.

Referenced by Rectangle().

◆ d_r

double util::geometry::Rectangle::d_r

Radius of bounding circle.

Definition at line 1021 of file geomObjects.h.

◆ d_vertices

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

Vertices.

Definition at line 1009 of file geomObjects.h.

Referenced by Rectangle(), and Rectangle().

◆ d_x

util::Point util::geometry::Rectangle::d_x

Center.

Definition at line 1012 of file geomObjects.h.


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