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

Defines cuboid. More...

#include <geomObjects.h>

Inheritance diagram for util::geometry::Cuboid:
Collaboration diagram for util::geometry::Cuboid:

Public Member Functions

 Cuboid ()
 Constructor.
 
 Cuboid (double Lx, double Ly, double Lz, util::Point x=util::Point(), std::string description="")
 Constructor.
 
 Cuboid (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 cuboid in x-direction.
 
double d_Ly
 Edge length of cuboid in y-direction.
 
double d_Lz
 Edge length of cuboid in z-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 cuboid.

Definition at line 1662 of file geomObjects.h.

Constructor & Destructor Documentation

◆ Cuboid() [1/3]

util::geometry::Cuboid::Cuboid ( )
inline

Constructor.

Definition at line 1668 of file geomObjects.h.

1669 : GeomObject("cuboid", ""),
1670 d_Lx(0.),
1671 d_Ly(0.),
1672 d_Lz(0.),
1673 d_r(0.),
1674 d_x(util::Point()),
1675 d_vertices(std::vector<util::Point>(8, util::Point())) {};
std::vector< util::Point > d_vertices
Vertices.
util::Point d_x
Center.
double d_Ly
Edge length of cuboid in y-direction.
double d_Lz
Edge length of cuboid in z-direction.
double d_r
Radius of bounding circle.
double d_Lx
Edge length of cuboid in x-direction.
GeomObject(std::string name="", std::string description="")
Constructor.
Definition geomObjects.h:39
A structure to represent 3d vectors.
Definition point.h:30

◆ Cuboid() [2/3]

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

Constructor.

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

Definition at line 1686 of file geomObjects.h.

1689 : GeomObject("cuboid", description),
1690 d_Lx(Lx),
1691 d_Ly(Ly),
1692 d_Lz(Lz),
1693 d_r(std::sqrt(std::pow(Lx, 2) + std::pow(Ly, 2) +
1694 std::pow(Lz, 2))),
1695 d_x(x),
1696 d_vertices(std::vector<util::Point>(8, util::Point())) {
1697 // numbering assuming x - left-right, y - back-front, z - bottom-top
1698 // counterclockwise in bottom plane (i.e.,
1699 // 0 - left-back-bottom, 1 - right-back-bottom,
1700 // 2 - right-front-bottom, 3 - left-front-bottom
1701 // similarly, in top plane
1702 d_vertices[0] =
1703 d_x + util::Point(-0.5 * d_Lx, -0.5 * d_Ly, -0.5 * d_Lz);
1704 d_vertices[1] =
1705 d_x + util::Point(0.5 * d_Lx, -0.5 * d_Ly, -0.5 * d_Lz);
1706 d_vertices[2] =
1707 d_x + util::Point(0.5 * d_Lx, 0.5 * d_Ly, -0.5 * d_Lz);
1708 d_vertices[3] =
1709 d_x + util::Point(-0.5 * d_Lx, 0.5 * d_Ly, -0.5 * d_Lz);
1710
1711 d_vertices[4] =
1712 d_x + util::Point(-0.5 * d_Lx, -0.5 * d_Ly, 0.5 * d_Lz);
1713 d_vertices[5] =
1714 d_x + util::Point(0.5 * d_Lx, -0.5 * d_Ly, 0.5 * d_Lz);
1715 d_vertices[6] =
1716 d_x + util::Point(0.5 * d_Lx, 0.5 * d_Ly, 0.5 * d_Lz);
1717 d_vertices[7] =
1718 d_x + util::Point(-0.5 * d_Lx, 0.5 * d_Ly, 0.5 * d_Lz);
1719 };

References d_Lx, d_Ly, d_Lz, d_vertices, and d_x.

◆ Cuboid() [3/3]

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

Constructor.

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

Definition at line 1728 of file geomObjects.h.

1729 : GeomObject("cuboid", description),
1730 d_Lx(x2.d_x - x1.d_x),
1731 d_Ly(x2.d_y - x1.d_y),
1732 d_Lz(x2.d_z - x1.d_z),
1733 d_r(std::sqrt(
1734 std::pow(x2.d_x - x1.d_x, 2)
1735 + std::pow(x2.d_y - x1.d_y, 2)
1736 + std::pow(x2.d_z - x1.d_z, 2)
1737 )
1738 ),
1739 d_x(0.5 * (x1 + x2)),
1740 d_vertices(std::vector<util::Point>(8, util::Point())) {
1741 // numbering assuming x - left-right, y - back-front, z - bottom-top
1742 // counterclockwise in bottom plane (i.e.,
1743 // 0 - left-back-bottom, 1 - right-back-bottom,
1744 // 2 - right-front-bottom, 3 - left-front-bottom
1745 // similarly, in top plane
1746 d_vertices[0] =
1747 d_x + util::Point(-0.5 * d_Lx, -0.5 * d_Ly, -0.5 * d_Lz);
1748 d_vertices[1] =
1749 d_x + util::Point(0.5 * d_Lx, -0.5 * d_Ly, -0.5 * d_Lz);
1750 d_vertices[2] =
1751 d_x + util::Point(0.5 * d_Lx, 0.5 * d_Ly, -0.5 * d_Lz);
1752 d_vertices[3] =
1753 d_x + util::Point(-0.5 * d_Lx, 0.5 * d_Ly, -0.5 * d_Lz);
1754
1755 d_vertices[4] =
1756 d_x + util::Point(-0.5 * d_Lx, -0.5 * d_Ly, 0.5 * d_Lz);
1757 d_vertices[5] =
1758 d_x + util::Point(0.5 * d_Lx, -0.5 * d_Ly, 0.5 * d_Lz);
1759 d_vertices[6] =
1760 d_x + util::Point(0.5 * d_Lx, 0.5 * d_Ly, 0.5 * d_Lz);
1761 d_vertices[7] =
1762 d_x + util::Point(-0.5 * d_Lx, 0.5 * d_Ly, 0.5 * d_Lz);
1763 };
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_Ly, d_Lz, d_vertices, and d_x.

Member Function Documentation

◆ boundingRadius()

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

1082 {
1083
1084 return d_r;
1085 }

◆ box() [1/2]

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

1063 {
1064
1065 return box(0.);
1066 }
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::Cuboid::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 1068 of file geomObjects.cpp.

1069 {
1070 return {util::Point(d_vertices[0].d_x - tol, d_vertices[0].d_y - tol,
1071 d_vertices[0].d_z - tol),
1072 util::Point(d_vertices[6].d_x + tol, d_vertices[6].d_y + tol,
1073 d_vertices[6].d_z + tol)};
1074 }

◆ center()

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

Computes the center of object.

Returns
Point Coordinates of center

Reimplemented from util::geometry::GeomObject.

Definition at line 1059 of file geomObjects.cpp.

1059 {
1060 return d_x;
1061 }

◆ doesIntersect() [1/2]

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

1158 {
1159
1160 // need to check all four corner points
1161 for (auto p: util::getCornerPoints(3, box))
1162 if (this->isInside(p))
1163 return true;
1164
1165 return false;
1166 }
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::Cuboid::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 1124 of file geomObjects.cpp.

1124 {
1125
1126 return isNearBoundary(x, 1.0E-8, false);
1127 }
bool isNearBoundary(const util::Point &x, const double &tol, const bool &within) const override
cons

◆ inscribedRadius()

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

1076 {
1077
1078 auto l = util::isLess(d_Lx, d_Ly) ? d_Lx : d_Ly;
1079 return util::isLess(l, d_Lz) ? l : d_Lz;
1080 }
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::Cuboid::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 1129 of file geomObjects.cpp.

1130 {
1131
1132 for (auto p: util::getCornerPoints(3, box))
1133 if (!this->isInside(p))
1134 return false;
1135
1136 return true;
1137 }

References util::getCornerPoints().

Here is the call graph for this function:

◆ isInside() [2/2]

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

1087 {
1089 }
bool isPointInsideCuboid(util::Point x, util::Point x_lbb, util::Point x_rtf)
Checks if point is inside a cuboid.
Definition geom.cpp:286

References util::isPointInsideCuboid().

Here is the call graph for this function:

◆ isNear() [1/2]

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

1152 {
1153
1154 return util::areBoxesNear(box(), bbox, tol, 3);
1155 }
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::Cuboid::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 1095 of file geomObjects.cpp.

1096 {
1097
1098 // get a bigger box containing this object
1099 auto bbox = box(tol);
1100
1101 return util::isPointInsideBox(x, 3, bbox);
1102 }
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::Cuboid::isNearBoundary ( const util::Point x,
const double &  tol,
const bool &  within 
) const
overridevirtual

cons

cons

Reimplemented from util::geometry::GeomObject.

Definition at line 1104 of file geomObjects.cpp.

1106 {
1107
1108 // check if particle is within the tolerance distance
1109 if (!isNear(x, within ? 0. : tol))
1110 return false;
1111
1112 bool near_x_edge = util::isLess(std::abs(x.d_x - d_vertices[0].d_x), tol) or
1113 util::isLess(std::abs(x.d_x - d_vertices[6].d_x), tol);
1114
1115 bool near_y_edge = util::isLess(std::abs(x.d_y - d_vertices[0].d_y), tol) or
1116 util::isLess(std::abs(x.d_y - d_vertices[6].d_y), tol);
1117
1118 bool near_z_edge = util::isLess(std::abs(x.d_z - d_vertices[0].d_z), tol) or
1119 util::isLess(std::abs(x.d_z - d_vertices[6].d_z), tol);
1120
1121 return near_x_edge || near_y_edge || near_z_edge;
1122 }
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, util::Point::d_z, and util::isLess().

Here is the call graph for this function:

◆ isOutside() [1/2]

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

1140 {
1141
1142 bool intersect = false;
1143 for (auto p: util::getCornerPoints(3, box))
1144 if (!intersect)
1145 intersect = this->isInside(p);
1146
1147 return !intersect;
1148 }

References util::getCornerPoints().

Here is the call graph for this function:

◆ isOutside() [2/2]

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

1091 {
1092 return !isInside(x);
1093 }

◆ print() [1/2]

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

Prints the information about the object.

Reimplemented from util::geometry::GeomObject.

Definition at line 1882 of file geomObjects.h.

1882{ 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::Cuboid::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 1875 of file geomObjects.h.

1875 {
1876 std::cout << printStr(nt, lvl);
1877 };
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::Cuboid::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 1168 of file geomObjects.cpp.

1168 {
1169
1170 auto tabS = util::io::getTabS(nt);
1171
1172 std::ostringstream oss;
1173
1174 oss << tabS << "------- Cuboid --------" << std::endl << std::endl;
1175 oss << tabS << "Name = " << d_name << std::endl;
1176 oss << tabS << "Lengths (Lx, Ly, Lz) = "
1177 << util::io::printStr(std::vector<double>{d_Lx, d_Ly, d_Lz}, 0)
1178 << std::endl;
1179 oss << tabS << "Bounding sphere radius = " << d_r << std::endl;
1180 oss << tabS << "Center = " << d_x.printStr(0, 0) << std::endl;
1181 oss << tabS << "Vertices = " << util::io::printStr(d_vertices, 0) << std::endl;
1182 oss << std::endl;
1183
1184 if (lvl > 0)
1185 oss << tabS << "Bounding box: "
1186 << util::io::printBoxStr(box(0.), nt + 1);
1187
1188 if (lvl == 0)
1189 oss << std::endl;
1190
1191 return oss.str();
1192 }
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
std::string printStr(int nt=0, int lvl=0) const
Returns the string containing printable information about the object.
Definition point.h:94

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::Cuboid::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 1055 of file geomObjects.cpp.

1055 {
1056 return d_Lx * d_Ly * d_Lz;
1057 }

Field Documentation

◆ d_Lx

double util::geometry::Cuboid::d_Lx

Edge length of cuboid in x-direction.

Definition at line 1891 of file geomObjects.h.

Referenced by Cuboid(), and Cuboid().

◆ d_Ly

double util::geometry::Cuboid::d_Ly

Edge length of cuboid in y-direction.

Definition at line 1894 of file geomObjects.h.

Referenced by Cuboid(), and Cuboid().

◆ d_Lz

double util::geometry::Cuboid::d_Lz

Edge length of cuboid in z-direction.

Definition at line 1897 of file geomObjects.h.

Referenced by Cuboid(), and Cuboid().

◆ d_r

double util::geometry::Cuboid::d_r

Radius of bounding circle.

Definition at line 1900 of file geomObjects.h.

◆ d_vertices

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

Vertices.

Definition at line 1885 of file geomObjects.h.

Referenced by Cuboid(), and Cuboid().

◆ d_x

util::Point util::geometry::Cuboid::d_x

Center.

Definition at line 1888 of file geomObjects.h.

Referenced by Cuboid(), and Cuboid().


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