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

Defines cube. More...

#include <geomObjects.h>

Inheritance diagram for util::geometry::Cube:
Collaboration diagram for util::geometry::Cube:

Public Member Functions

 Cube ()
 Constructor.
 
 Cube (double L, util::Point x=util::Point(), std::string description="")
 Constructor.
 
 Cube (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_L
 Edge length of cube.
 
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 cube.

Definition at line 1439 of file geomObjects.h.

Constructor & Destructor Documentation

◆ Cube() [1/3]

util::geometry::Cube::Cube ( )
inline

Constructor.

Definition at line 1445 of file geomObjects.h.

1446 : GeomObject("cube", ""),
1447 d_L(0.),
1448 d_r(0.),
1449 d_x(util::Point()),
1450 d_vertices(std::vector<util::Point>(8, util::Point())) {};
double d_L
Edge length of cube.
util::Point d_x
Center.
std::vector< util::Point > d_vertices
Vertices.
double d_r
Radius of bounding circle.
GeomObject(std::string name="", std::string description="")
Constructor.
Definition geomObjects.h:39
A structure to represent 3d vectors.
Definition point.h:30

◆ Cube() [2/3]

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

Constructor.

Parameters
LLength along x, y, and z-direction
xCoordinate of center
descriptionDescription of object (e.g., further classification or any tag)

Definition at line 1459 of file geomObjects.h.

1461 : GeomObject("cube", description),
1462 d_L(L),
1463 d_r(0.5 * std::sqrt(3.) * L),
1464 d_x(x),
1465 d_vertices(std::vector<util::Point>(8, util::Point())) {
1466 // numbering assuming x - left-right, y - back-front, z - bottom-top
1467 // counterclockwise in bottom plane (i.e.,
1468 // 0 - left-back-bottom, 1 - right-back-bottom,
1469 // 2 - right-front-bottom, 3 - left-front-bottom
1470 // similarly, in top plane
1471 d_vertices[0] =
1472 d_x + util::Point(-0.5 * d_L, -0.5 * d_L, -0.5 * d_L);
1473 d_vertices[1] =
1474 d_x + util::Point(0.5 * d_L, -0.5 * d_L, -0.5 * d_L);
1475 d_vertices[2] =
1476 d_x + util::Point(0.5 * d_L, 0.5 * d_L, -0.5 * d_L);
1477 d_vertices[3] =
1478 d_x + util::Point(-0.5 * d_L, 0.5 * d_L, -0.5 * d_L);
1479
1480 d_vertices[4] =
1481 d_x + util::Point(-0.5 * d_L, -0.5 * d_L, 0.5 * d_L);
1482 d_vertices[5] =
1483 d_x + util::Point(0.5 * d_L, -0.5 * d_L, 0.5 * d_L);
1484 d_vertices[6] =
1485 d_x + util::Point(0.5 * d_L, 0.5 * d_L, 0.5 * d_L);
1486 d_vertices[7] =
1487 d_x + util::Point(-0.5 * d_L, 0.5 * d_L, 0.5 * d_L);
1488 };

References d_L, d_vertices, and d_x.

◆ Cube() [3/3]

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

1498 : GeomObject("cube", description),
1499 d_L((x2 - x1).length() / std::sqrt(3.)),
1500 d_r(0.5 * (x2 - x1).length()),
1501 d_x(0.5 * (x1 + x2)),
1502 d_vertices(std::vector<util::Point>(8, util::Point())) {
1503 // numbering assuming x - left-right, y - back-front, z - bottom-top
1504 // counterclockwise in bottom plane (i.e.,
1505 // 0 - left-back-bottom, 1 - right-back-bottom,
1506 // 2 - right-front-bottom, 3 - left-front-bottom
1507 // similarly, in top plane
1508 d_vertices[0] =
1509 d_x + util::Point(-0.5 * d_L, -0.5 * d_L, -0.5 * d_L);
1510 d_vertices[1] =
1511 d_x + util::Point(0.5 * d_L, -0.5 * d_L, -0.5 * d_L);
1512 d_vertices[2] =
1513 d_x + util::Point(0.5 * d_L, 0.5 * d_L, -0.5 * d_L);
1514 d_vertices[3] =
1515 d_x + util::Point(-0.5 * d_L, 0.5 * d_L, -0.5 * d_L);
1516
1517 d_vertices[4] =
1518 d_x + util::Point(-0.5 * d_L, -0.5 * d_L, 0.5 * d_L);
1519 d_vertices[5] =
1520 d_x + util::Point(0.5 * d_L, -0.5 * d_L, 0.5 * d_L);
1521 d_vertices[6] =
1522 d_x + util::Point(0.5 * d_L, 0.5 * d_L, 0.5 * d_L);
1523 d_vertices[7] =
1524 d_x + util::Point(-0.5 * d_L, 0.5 * d_L, 0.5 * d_L);
1525 };

References d_L, d_vertices, and d_x.

Member Function Documentation

◆ boundingRadius()

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

940 {
941
942 return d_r;
943 }

◆ box() [1/2]

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

922 {
923
924 return box(0.);
925 }
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::Cube::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 927 of file geomObjects.cpp.

928 {
929 return {util::Point(d_vertices[0].d_x - tol, d_vertices[0].d_y - tol,
930 d_vertices[0].d_z - tol),
931 util::Point(d_vertices[6].d_x + tol, d_vertices[6].d_y + tol,
932 d_vertices[6].d_z + tol)};
933 }

◆ center()

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

Computes the center of object.

Returns
Point Coordinates of center

Reimplemented from util::geometry::GeomObject.

Definition at line 918 of file geomObjects.cpp.

918 {
919 return d_x;
920 }

◆ doesIntersect() [1/2]

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

1016 {
1017
1018 // need to check all four corner points
1019 for (auto p: util::getCornerPoints(3, box))
1020 if (this->isInside(p))
1021 return true;
1022
1023 return false;
1024 }
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::Cube::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 982 of file geomObjects.cpp.

982 {
983
984 return isNearBoundary(x, 1.0E-8, false);
985 }
bool isNearBoundary(const util::Point &x, const double &tol, const bool &within) const override
cons

◆ inscribedRadius()

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

935 {
936
937 return d_L;
938 }

◆ isInside() [1/2]

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

988 {
989
990 for (auto p: util::getCornerPoints(3, box))
991 if (!this->isInside(p))
992 return false;
993
994 return true;
995 }

References util::getCornerPoints().

Here is the call graph for this function:

◆ isInside() [2/2]

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

945 {
947 }
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::Cube::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 1008 of file geomObjects.cpp.

1010 {
1011
1012 return util::areBoxesNear(box(), bbox, tol, 3);
1013 }
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::Cube::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 953 of file geomObjects.cpp.

954 {
955
956 // get a bigger box containing this object
957 auto bbox = box(tol);
958
959 return util::isPointInsideBox(x, 3, bbox);
960 }
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::Cube::isNearBoundary ( const util::Point x,
const double &  tol,
const bool &  within 
) const
overridevirtual

cons

cons

Reimplemented from util::geometry::GeomObject.

Definition at line 962 of file geomObjects.cpp.

964 {
965
966 // check if particle is within the tolerance distance
967 if (!isNear(x, within ? 0. : tol))
968 return false;
969
970 bool near_x_edge = util::isLess(std::abs(x.d_x - d_vertices[0].d_x), tol) or
971 util::isLess(std::abs(x.d_x - d_vertices[6].d_x), tol);
972
973 bool near_y_edge = util::isLess(std::abs(x.d_y - d_vertices[0].d_y), tol) or
974 util::isLess(std::abs(x.d_y - d_vertices[6].d_y), tol);
975
976 bool near_z_edge = util::isLess(std::abs(x.d_z - d_vertices[0].d_z), tol) or
977 util::isLess(std::abs(x.d_z - d_vertices[6].d_z), tol);
978
979 return near_x_edge || near_y_edge || near_z_edge;
980 }
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
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 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::Cube::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 997 of file geomObjects.cpp.

998 {
999
1000 bool intersect = false;
1001 for (auto p: util::getCornerPoints(3, box))
1002 if (!intersect)
1003 intersect = this->isInside(p);
1004
1005 return !intersect;
1006 }

References util::getCornerPoints().

Here is the call graph for this function:

◆ isOutside() [2/2]

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

949 {
950 return !isInside(x);
951 }

◆ print() [1/2]

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

Prints the information about the object.

Reimplemented from util::geometry::GeomObject.

Definition at line 1644 of file geomObjects.h.

1644{ 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::Cube::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 1637 of file geomObjects.h.

1637 {
1638 std::cout << printStr(nt, lvl);
1639 };
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::Cube::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 1026 of file geomObjects.cpp.

1026 {
1027
1028 auto tabS = util::io::getTabS(nt);
1029
1030 std::ostringstream oss;
1031
1032 oss << tabS << "------- Cube --------" << std::endl << std::endl;
1033 oss << tabS << "Name = " << d_name << std::endl;
1034 oss << tabS << "Length = " << d_L << std::endl;
1035 oss << tabS << "Bounding sphere radius = " << d_r << std::endl;
1036 oss << tabS << "Center = " << d_x.printStr(0, 0) << std::endl;
1037 oss << tabS << "Vertices = " << util::io::printStr(d_vertices, 0) << std::endl;
1038 oss << std::endl;
1039
1040 if (lvl > 0)
1041 oss << tabS << "Bounding box: "
1042 << util::io::printBoxStr(box(0.), nt + 1);
1043
1044 if (lvl == 0)
1045 oss << std::endl;
1046
1047 return oss.str();
1048 }
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::Cube::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 914 of file geomObjects.cpp.

914 {
915 return std::pow(d_L, 3);
916 }

Field Documentation

◆ d_L

double util::geometry::Cube::d_L

Edge length of cube.

Definition at line 1653 of file geomObjects.h.

Referenced by Cube(), and Cube().

◆ d_r

double util::geometry::Cube::d_r

Radius of bounding circle.

Definition at line 1656 of file geomObjects.h.

◆ d_vertices

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

Vertices.

Definition at line 1647 of file geomObjects.h.

Referenced by Cube(), and Cube().

◆ d_x

util::Point util::geometry::Cube::d_x

Center.

Definition at line 1650 of file geomObjects.h.

Referenced by Cube(), and Cube().


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