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

Defines cube. More...

#include <geomObjects.h>

Inheritance diagram for geom::Cube:
Collaboration diagram for geom::Cube:

Public Member Functions

 Cube ()
 Constructor.
 
 Cube (double L, util::Point x=util::Point(), std::string description="")
 Constructor.
 
 Cube (const Cube &other)
 Copy constructor.
 
 Cube (util::Point x1, util::Point x2, std::string description="")
 Constructor.
 
Cubeoperator= (const Cube &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 cube.
 
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 cube.

Definition at line 1991 of file geomObjects.h.

Constructor & Destructor Documentation

◆ Cube() [1/4]

geom::Cube::Cube ( )
inline

Constructor.

Definition at line 2009 of file geomObjects.h.

2010 : GeomObject("cube", ""),
2011 d_L(0.),
2012 d_r(0.),
2013 d_x(util::Point()),
2014 d_vertices(std::vector<util::Point>(8, util::Point())) {
2015 };
util::Point d_x
Center.
double d_r
Radius of bounding circle.
std::vector< util::Point > d_vertices
Vertices.
double d_L
Edge length of cube.
GeomObject(std::string name="", std::string description="")
Constructor.
A structure to represent 3d vectors.
Definition point.h:30

◆ Cube() [2/4]

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

2026 : GeomObject("cube", description),
2027 d_L(L),
2028 d_r(0.5 * std::sqrt(3.) * L),
2029 d_x(x),
2030 d_vertices(std::vector<util::Point>(8, util::Point())) {
2031 // numbering assuming x - left-right, y - back-front, z - bottom-top
2032 // counterclockwise in bottom plane (i.e.,
2033 // 0 - left-back-bottom, 1 - right-back-bottom,
2034 // 2 - right-front-bottom, 3 - left-front-bottom
2035 // similarly, in top plane
2036 d_vertices[0] =
2037 d_x + util::Point(-0.5 * d_L, -0.5 * d_L, -0.5 * d_L);
2038 d_vertices[1] =
2039 d_x + util::Point(0.5 * d_L, -0.5 * d_L, -0.5 * d_L);
2040 d_vertices[2] =
2041 d_x + util::Point(0.5 * d_L, 0.5 * d_L, -0.5 * d_L);
2042 d_vertices[3] =
2043 d_x + util::Point(-0.5 * d_L, 0.5 * d_L, -0.5 * d_L);
2044
2045 d_vertices[4] =
2046 d_x + util::Point(-0.5 * d_L, -0.5 * d_L, 0.5 * d_L);
2047 d_vertices[5] =
2048 d_x + util::Point(0.5 * d_L, -0.5 * d_L, 0.5 * d_L);
2049 d_vertices[6] =
2050 d_x + util::Point(0.5 * d_L, 0.5 * d_L, 0.5 * d_L);
2051 d_vertices[7] =
2052 d_x + util::Point(-0.5 * d_L, 0.5 * d_L, 0.5 * d_L);
2053 };

References d_L, d_vertices, and d_x.

◆ Cube() [3/4]

geom::Cube::Cube ( const Cube other)
inline

Copy constructor.

Parameters
otherObject to copy from

Definition at line 2059 of file geomObjects.h.

2060 : GeomObject(other.d_name, other.d_description),
2061 d_L(other.d_L),
2062 d_r(other.d_r),
2063 d_x(other.d_x),
2064 d_vertices(other.d_vertices) {
2065 d_tags = other.d_tags;
2066 }
std::vector< std::string > d_tags
Tags/attributes about the object.

References geom::GeomObject::d_tags.

◆ Cube() [4/4]

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

2076 : GeomObject("cube", description),
2077 d_L((x2 - x1).length() / std::sqrt(3.)),
2078 d_r(0.5 * (x2 - x1).length()),
2079 d_x(0.5 * (x1 + x2)),
2080 d_vertices(std::vector<util::Point>(8, util::Point())) {
2081 // numbering assuming x - left-right, y - back-front, z - bottom-top
2082 // counterclockwise in bottom plane (i.e.,
2083 // 0 - left-back-bottom, 1 - right-back-bottom,
2084 // 2 - right-front-bottom, 3 - left-front-bottom
2085 // similarly, in top plane
2086 d_vertices[0] =
2087 d_x + util::Point(-0.5 * d_L, -0.5 * d_L, -0.5 * d_L);
2088 d_vertices[1] =
2089 d_x + util::Point(0.5 * d_L, -0.5 * d_L, -0.5 * d_L);
2090 d_vertices[2] =
2091 d_x + util::Point(0.5 * d_L, 0.5 * d_L, -0.5 * d_L);
2092 d_vertices[3] =
2093 d_x + util::Point(-0.5 * d_L, 0.5 * d_L, -0.5 * d_L);
2094
2095 d_vertices[4] =
2096 d_x + util::Point(-0.5 * d_L, -0.5 * d_L, 0.5 * d_L);
2097 d_vertices[5] =
2098 d_x + util::Point(0.5 * d_L, -0.5 * d_L, 0.5 * d_L);
2099 d_vertices[6] =
2100 d_x + util::Point(0.5 * d_L, 0.5 * d_L, 0.5 * d_L);
2101 d_vertices[7] =
2102 d_x + util::Point(-0.5 * d_L, 0.5 * d_L, 0.5 * d_L);
2103 };

References d_L, d_vertices, and d_x.

Member Function Documentation

◆ boundingRadius()

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

Definition at line 1089 of file geomObjects.cpp.

1089 {
1090
1091 return d_r;
1092 }

References d_r.

◆ box() [1/2]

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

Definition at line 1071 of file geomObjects.cpp.

1071 {
1072
1073 return box(0.);
1074 }
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::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 geom::GeomObject.

Definition at line 1076 of file geomObjects.cpp.

1077 {
1078 return {util::Point(d_vertices[0].d_x - tol, d_vertices[0].d_y - tol,
1079 d_vertices[0].d_z - tol),
1080 util::Point(d_vertices[6].d_x + tol, d_vertices[6].d_y + tol,
1081 d_vertices[6].d_z + tol)};
1082 }

References d_vertices, and d_x.

◆ center()

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

Computes the center of object.

Returns
Point Coordinates of center

Reimplemented from geom::GeomObject.

Definition at line 1067 of file geomObjects.cpp.

1067 {
1068 return d_x;
1069 }

References d_x.

◆ doesIntersect() [1/2]

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

Definition at line 1164 of file geomObjects.cpp.

1165 {
1166
1167 // need to check all four corner points
1168 for (auto p: geom::getCornerPoints(3, box))
1169 if (this->isInside(p))
1170 return true;
1171
1172 return false;
1173 }
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::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 geom::GeomObject.

Definition at line 1131 of file geomObjects.cpp.

1131 {
1132
1133 return isNearBoundary(x, 1.0E-8, false);
1134 }
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::Cube::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 1084 of file geomObjects.cpp.

1084 {
1085
1086 return d_L;
1087 }

References d_L.

◆ isInside() [1/2]

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

Definition at line 1136 of file geomObjects.cpp.

1137 {
1138
1139 for (auto p: geom::getCornerPoints(3, box))
1140 if (!this->isInside(p))
1141 return false;
1142
1143 return true;
1144 }

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

Here is the call graph for this function:

◆ isInside() [2/2]

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

Definition at line 1094 of file geomObjects.cpp.

1094 {
1096 }
bool isPointInsideCuboid(util::Point x, util::Point x_lbb, util::Point x_rtf)
Checks if point is inside a cuboid.

References d_vertices, and geom::isPointInsideCuboid().

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

Definition at line 1157 of file geomObjects.cpp.

1159 {
1160
1161 return geom::areBoxesNear(box(), bbox, tol, 3);
1162 }
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::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 geom::GeomObject.

Definition at line 1102 of file geomObjects.cpp.

1103 {
1104
1105 // get a bigger box containing this object
1106 auto bbox = box(tol);
1107
1108 return geom::isPointInsideBox(x, 3, bbox);
1109 }
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::Cube::isNearBoundary ( const util::Point x,
const double &  tol,
const bool &  within 
) const
overridevirtual

cons

cons

Reimplemented from geom::GeomObject.

Definition at line 1111 of file geomObjects.cpp.

1113 {
1114
1115 // check if particle is within the tolerance distance
1116 if (!isNear(x, within ? 0. : tol))
1117 return false;
1118
1119 bool near_x_edge = util::isLess(std::abs(x.d_x - d_vertices[0].d_x), tol) or
1120 util::isLess(std::abs(x.d_x - d_vertices[6].d_x), tol);
1121
1122 bool near_y_edge = util::isLess(std::abs(x.d_y - d_vertices[0].d_y), tol) or
1123 util::isLess(std::abs(x.d_y - d_vertices[6].d_y), tol);
1124
1125 bool near_z_edge = util::isLess(std::abs(x.d_z - d_vertices[0].d_z), tol) or
1126 util::isLess(std::abs(x.d_z - d_vertices[6].d_z), tol);
1127
1128 return near_x_edge || near_y_edge || near_z_edge;
1129 }
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 d_vertices, util::Point::d_x, util::Point::d_y, util::Point::d_z, 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::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 geom::GeomObject.

Definition at line 1146 of file geomObjects.cpp.

1147 {
1148
1149 bool intersect = false;
1150 for (auto p: geom::getCornerPoints(3, box))
1151 if (!intersect)
1152 intersect = this->isInside(p);
1153
1154 return !intersect;
1155 }

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

Here is the call graph for this function:

◆ isOutside() [2/2]

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

Definition at line 1098 of file geomObjects.cpp.

1098 {
1099 return !isInside(x);
1100 }

References isInside().

Here is the call graph for this function:

◆ operator=()

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

Assignment operator.

Parameters
otherObject to copy from
Returns
Reference to this object

Definition at line 2110 of file geomObjects.h.

2110 {
2111 if (this != &other) {
2112 // Copy base class members
2113 d_tags = other.d_tags;
2114
2115 // Copy member variables
2116 d_L = other.d_L;
2117 d_r = other.d_r;
2118 d_x = other.d_x;
2119 d_vertices = other.d_vertices;
2120 }
2121 return *this;
2122 }

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

◆ print() [1/2]

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

Prints the information about the object.

Reimplemented from geom::GeomObject.

Definition at line 2255 of file geomObjects.h.

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

Definition at line 2248 of file geomObjects.h.

2248 {
2249 std::cout << printStr(nt, lvl);
2250 };
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::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 geom::GeomObject.

Definition at line 1175 of file geomObjects.cpp.

1175 {
1176
1177 auto tabS = util::io::getTabS(nt);
1178
1179 std::ostringstream oss;
1180
1181 oss << tabS << "------- Cube --------" << std::endl << std::endl;
1182 oss << tabS << "Name = " << d_name << std::endl;
1183 oss << tabS << "Length = " << d_L << std::endl;
1184 oss << tabS << "Bounding sphere radius = " << d_r << std::endl;
1185 oss << tabS << "Center = " << d_x.printStr(0, 0) << std::endl;
1186 oss << tabS << "Vertices = " << util::io::printStr(d_vertices, 0) << std::endl;
1187 oss << std::endl;
1188
1189 if (lvl > 0)
1190 oss << tabS << "Bounding box: "
1191 << util::io::printBoxStr(box(0.), nt + 1);
1192
1193 if (lvl == 0)
1194 oss << std::endl;
1195
1196 return oss.str();
1197 }
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::Cube::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 2125 of file geomObjects.h.

2126 {
2127 // Scale the dimensions
2128 d_L *= scale;
2129 d_r *= scale;
2130
2131 const util::Point c0 = d_x;
2132 for (auto &v : d_vertices) {
2133 v = mapSimilarity(v, c0, translation, scale, angle, axis, rotationPoint);
2134 }
2135 d_x = mapSimilarity(c0, c0, translation, scale, angle, axis, rotationPoint);
2136 }
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::Cube::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 1063 of file geomObjects.cpp.

1063 {
1064 return std::pow(d_L, 3);
1065 }

References d_L.

Field Documentation

◆ d_L

double geom::Cube::d_L

Edge length of cube.

Definition at line 2000 of file geomObjects.h.

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

◆ d_r

double geom::Cube::d_r

Radius of bounding circle.

Definition at line 2003 of file geomObjects.h.

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

◆ d_vertices

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

Vertices.

Definition at line 1994 of file geomObjects.h.

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

◆ d_x

util::Point geom::Cube::d_x

Center.

Definition at line 1997 of file geomObjects.h.

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


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