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

Defines cylinder. More...

#include <geomObjects.h>

Inheritance diagram for util::geometry::Cylinder:
Collaboration diagram for util::geometry::Cylinder:

Public Member Functions

 Cylinder ()
 Constructor.
 
 Cylinder (double r, double l, util::Point x_begin, util::Point xa, std::string description="")
 Constructor.
 
 Cylinder (double r, util::Point x_begin, util::Point xa, 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

util::Point d_x
 Center.
 
util::Point d_xBegin
 Center point of cross-section at the beginning.
 
util::Point d_xa
 Axis of cylinder (unit vector)
 
double d_r
 Radius.
 
double d_l
 Length.
 
- 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 cylinder.

Definition at line 2212 of file geomObjects.h.

Constructor & Destructor Documentation

◆ Cylinder() [1/3]

util::geometry::Cylinder::Cylinder ( )
inline

Constructor.

Definition at line 2218 of file geomObjects.h.

2219 : GeomObject("cylinder", ""),
2221 d_xa(util::Point(1., 1., 1.)),
2222 d_r(0.),
2223 d_l(0.),
2224 d_x(util::Point()) {};
util::Point d_xBegin
Center point of cross-section at the beginning.
util::Point d_xa
Axis of cylinder (unit vector)
util::Point d_x
Center.
GeomObject(std::string name="", std::string description="")
Constructor.
Definition geomObjects.h:39
A structure to represent 3d vectors.
Definition point.h:30

◆ Cylinder() [2/3]

util::geometry::Cylinder::Cylinder ( double  r,
double  l,
util::Point  x_begin,
util::Point  xa,
std::string  description = "" 
)
inline

Constructor.

Parameters
rRadius of cylinder
lLength of cylinder
x_beginCenter of the bottom bottom cross-section
xaAxis of cylinder (if it is not a unit vector, we compute unit vector along xa)
descriptionDescription of object (e.g., further classification or any tag)

Definition at line 2235 of file geomObjects.h.

2237 : GeomObject("cylinder", description),
2238 d_xBegin(x_begin),
2239 d_xa(xa / xa.length()),
2240 d_r(r),
2241 d_l(l),
2242 d_x(x_begin + 0.5 * l * xa) {};
double length() const
Computes the Euclidean length of the vector.
Definition point.h:118

◆ Cylinder() [3/3]

util::geometry::Cylinder::Cylinder ( double  r,
util::Point  x_begin,
util::Point  xa,
std::string  description = "" 
)
inline

Constructor.

Parameters
rRadius of cylinder
x_beginCenter of the bottom bottom cross-section
xaAxis of cylinder (should be the actual vector from center of bottom section to top section so that the length of the vector is a length of cylinder)
descriptionDescription of object (e.g., further classification or any tag)

Definition at line 2253 of file geomObjects.h.

2255 : GeomObject("cylinder", description),
2256 d_xBegin(x_begin),
2257 d_xa(xa / xa.length()),
2258 d_r(r),
2259 d_l(xa.length()),
2260 d_x(x_begin + 0.5 * xa.length() * xa) {};

Member Function Documentation

◆ boundingRadius()

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

1392 {
1393
1394 return 0.5 * std::sqrt(d_l * d_l + 4. * d_r * d_r);
1395 }

◆ box() [1/2]

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

1366 {
1367
1368 return box(0.);
1369 }
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::Cylinder::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 1372 of file geomObjects.cpp.

1372 {
1373
1374 if (d_xa.length() < 1.0E-10)
1375 return {util::Point(), util::Point()};
1376
1377 auto xb = d_xBegin - tol * d_xa;
1378 auto xt = d_xBegin + (d_l + tol) * d_xa;
1379
1380 double r = d_r + tol;
1381
1382 return {xb - r, xt + r};
1383 }

◆ center()

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

Computes the center of object.

Returns
Point Coordinates of center

Reimplemented from util::geometry::GeomObject.

Definition at line 1362 of file geomObjects.cpp.

1362 {
1363 return d_x;
1364 }

◆ doesIntersect() [1/2]

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

1501 {
1502
1503 // need to check all four corner points
1504 for (auto p: util::getCornerPoints(3, box))
1505 if (this->isInside(p))
1506 return true;
1507
1508 return false;
1509 }
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::Cylinder::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 1467 of file geomObjects.cpp.

1467 {
1468
1469 return isNearBoundary(x, 1.0E-8, false);
1470 }
bool isNearBoundary(const util::Point &x, const double &tol, const bool &within) const override
cons

◆ inscribedRadius()

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

1385 {
1386
1387 auto box = this->box();
1388
1389 return 0.5 * (box.second - box.first).length();
1390 }

◆ isInside() [1/2]

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

1473 {
1474
1475 for (auto p: util::getCornerPoints(3, box))
1476 if (!this->isInside(p))
1477 return false;
1478
1479 return true;
1480 }

References util::getCornerPoints().

Here is the call graph for this function:

◆ isInside() [2/2]

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

1397 {
1398
1399 auto dx = x - d_xBegin;
1400
1401 if (dx.length() < 1.0E-10)
1402 return true;
1403
1404 double dx_dot_xa = dx * d_xa;
1405 if (util::isLess(dx_dot_xa, 0.) or
1406 util::isGreater(dx_dot_xa, d_l))
1407 return false;
1408 else {
1409
1410 // project dx onto cross-section plane of cylinder
1411 auto dx_project = dx - dx_dot_xa * d_xa;
1412
1413 return !util::isGreater(dx_project.length(), d_r + 1.0E-12);
1414 }
1415 }
bool isGreater(const double &a, const double &b)
Returns true if a > b.
Definition function.cpp:15
bool isLess(const double &a, const double &b)
Returns true if a < b.
Definition function.cpp:20

References util::isGreater(), and util::isLess().

Here is the call graph for this function:

◆ isNear() [1/2]

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

1495 {
1496
1497 return util::areBoxesNear(this->box(), box, tol, 3);
1498 }
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::Cylinder::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 1421 of file geomObjects.cpp.

1422 {
1423
1424 auto dx = x - d_xBegin;
1425
1426 if (dx.length() < tol)
1427 return true;
1428
1429 double dx_dot_xa = dx * d_xa;
1430 if (util::isLess(dx_dot_xa, -tol) or
1431 util::isGreater(dx_dot_xa, d_l + tol))
1432 return false;
1433 else {
1434
1435 // project dx onto cross-section plane of cylinder
1436 auto dx_project = dx - dx_dot_xa * d_xa;
1437
1438 return !util::isGreater(dx_project.length(), d_r + tol);
1439 }
1440 }

References util::isGreater(), and util::isLess().

Here is the call graph for this function:

◆ isNearBoundary()

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

cons

cons

Reimplemented from util::geometry::GeomObject.

Definition at line 1442 of file geomObjects.cpp.

1444 {
1445
1446 auto dx = x - d_xBegin;
1447
1448 if (dx.length() < tol)
1449 return true;
1450
1451 double dx_dot_xa = dx * d_xa;
1452 if (util::isLess(dx_dot_xa, -tol) or
1453 util::isGreater(dx_dot_xa, tol) or
1454 util::isGreater(dx_dot_xa, d_l + tol) or
1455 util::isLess(dx_dot_xa, d_l - tol))
1456 return false;
1457 else {
1458
1459 // project dx onto cross-section plane of cylinder
1460 auto dx_project = dx - dx_dot_xa * d_xa;
1461
1462 return !(util::isLess(dx_project.length(), d_r - tol) or
1463 util::isGreater(dx_project.length(), d_r + tol));
1464 }
1465 }

References util::isGreater(), and util::isLess().

Here is the call graph for this function:

◆ isOutside() [1/2]

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

1483 {
1484
1485 bool intersect = false;
1486 for (auto p: util::getCornerPoints(3, box))
1487 if (!intersect)
1488 intersect = this->isInside(p);
1489
1490 return !intersect;
1491 }

References util::getCornerPoints().

Here is the call graph for this function:

◆ isOutside() [2/2]

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

1417 {
1418 return !isInside(x);
1419 }

◆ print() [1/2]

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

Prints the information about the object.

Reimplemented from util::geometry::GeomObject.

Definition at line 2379 of file geomObjects.h.

2379{ 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::Cylinder::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 2372 of file geomObjects.h.

2372 {
2373 std::cout << printStr(nt, lvl);
2374 };
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::Cylinder::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 1512 of file geomObjects.cpp.

1512 {
1513
1514 auto tabS = util::io::getTabS(nt);
1515
1516 std::ostringstream oss;
1517
1518 oss << tabS << "------- Cylinder --------" << std::endl << std::endl;
1519 oss << tabS << "Name = " << d_name << std::endl;
1520 oss << tabS << "Center = " << d_xBegin.printStr(0, lvl) << std::endl;
1521 oss << tabS << "Axis = " << d_xa.printStr(0, lvl) << std::endl;
1522 oss << tabS << "Radius = " << d_r << std::endl;
1523 oss << tabS << "Center = " << d_x.printStr(0, 0) << std::endl;
1524
1525 if (lvl > 0)
1526 oss << tabS << "Bounding box: "
1527 << util::io::printBoxStr(box(0.), nt + 1);
1528
1529 if (lvl == 0)
1530 oss << std::endl;
1531
1532 return oss.str();
1533 }
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(int nt=0, int lvl=0) const
Returns the string containing printable information about the object.
Definition point.h:94

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

Referenced by print().

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

◆ volume()

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

1358 {
1359 return M_PI * d_r * d_r * d_l;
1360 }

Field Documentation

◆ d_l

double util::geometry::Cylinder::d_l

Length.

Definition at line 2394 of file geomObjects.h.

◆ d_r

double util::geometry::Cylinder::d_r

Radius.

Definition at line 2391 of file geomObjects.h.

◆ d_x

util::Point util::geometry::Cylinder::d_x

Center.

Definition at line 2382 of file geomObjects.h.

◆ d_xa

util::Point util::geometry::Cylinder::d_xa

Axis of cylinder (unit vector)

Definition at line 2388 of file geomObjects.h.

◆ d_xBegin

util::Point util::geometry::Cylinder::d_xBegin

Center point of cross-section at the beginning.

Definition at line 2385 of file geomObjects.h.


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