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

Defines cylinder. More...

#include <geomObjects.h>

Inheritance diagram for geom::Cylinder:
Collaboration diagram for geom::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.
 
 Cylinder (const Cylinder &other)
 Copy constructor.
 
Cylinderoperator= (const Cylinder &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

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 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 cylinder.

Definition at line 3139 of file geomObjects.h.

Constructor & Destructor Documentation

◆ Cylinder() [1/4]

geom::Cylinder::Cylinder ( )
inline

Constructor.

Definition at line 3160 of file geomObjects.h.

3161 : GeomObject("cylinder", ""),
3163 d_xa(util::Point(1., 1., 1.)),
3164 d_r(0.),
3165 d_l(0.),
3166 d_x(util::Point()) {
3167 };
util::Point d_xBegin
Center point of cross-section at the beginning.
util::Point d_xa
Axis of cylinder (unit vector)
double d_l
Length.
util::Point d_x
Center.
double d_r
Radius.
GeomObject(std::string name="", std::string description="")
Constructor.
A structure to represent 3d vectors.
Definition point.h:30

◆ Cylinder() [2/4]

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

3180 : GeomObject("cylinder", description),
3181 d_xBegin(x_begin),
3182 d_xa(xa / xa.length()),
3183 d_r(r),
3184 d_l(l),
3185 d_x(x_begin + 0.5 * l * (xa / xa.length())) {
3186 };
double length() const
Computes the Euclidean length of the vector.
Definition point.h:124

◆ Cylinder() [3/4]

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

3199 : GeomObject("cylinder", description),
3200 d_xBegin(x_begin),
3201 d_xa(xa / xa.length()),
3202 d_r(r),
3203 d_l(xa.length()),
3204 d_x(x_begin + 0.5 * xa) {};

◆ Cylinder() [4/4]

geom::Cylinder::Cylinder ( const Cylinder other)
inline

Copy constructor.

Parameters
otherObject to copy from

Definition at line 3210 of file geomObjects.h.

3211 : GeomObject(other.d_name, other.d_description),
3212 d_xBegin(other.d_xBegin),
3213 d_xa(other.d_xa),
3214 d_r(other.d_r),
3215 d_l(other.d_l),
3216 d_x(other.d_x) {
3217 d_tags = other.d_tags;
3218 }
std::vector< std::string > d_tags
Tags/attributes about the object.

References geom::GeomObject::d_tags.

Member Function Documentation

◆ boundingRadius()

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

Definition at line 1696 of file geomObjects.cpp.

1696 {
1697
1698 return 0.5 * std::sqrt(d_l * d_l + 4. * d_r * d_r);
1699 }

References d_l, and d_r.

◆ box() [1/2]

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

Definition at line 1670 of file geomObjects.cpp.

1670 {
1671
1672 return box(0.);
1673 }
std::pair< util::Point, util::Point > box() const override
Computes the bounding box of object.

References box().

Referenced by box(), doesIntersect(), inscribedRadius(), isInside(), 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::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 geom::GeomObject.

Definition at line 1676 of file geomObjects.cpp.

1676 {
1677
1678 if (d_xa.length() < 1.0E-10)
1679 return {util::Point(), util::Point()};
1680
1681 auto xb = d_xBegin - tol * d_xa;
1682 auto xt = d_xBegin + (d_l + tol) * d_xa;
1683
1684 double r = d_r + tol;
1685
1686 return {xb - r, xt + r};
1687 }

References d_l, d_r, d_xa, d_xBegin, and util::Point::length().

Here is the call graph for this function:

◆ center()

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

Computes the center of object.

Returns
Point Coordinates of center

Reimplemented from geom::GeomObject.

Definition at line 1666 of file geomObjects.cpp.

1666 {
1667 return d_x;
1668 }

References d_x.

◆ doesIntersect() [1/2]

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

Definition at line 1804 of file geomObjects.cpp.

1805 {
1806
1807 // need to check all four corner points
1808 for (auto p: geom::getCornerPoints(3, box))
1809 if (this->isInside(p))
1810 return true;
1811
1812 return false;
1813 }
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::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 geom::GeomObject.

Definition at line 1771 of file geomObjects.cpp.

1771 {
1772
1773 return isNearBoundary(x, 1.0E-8, false);
1774 }
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::Cylinder::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 1689 of file geomObjects.cpp.

1689 {
1690
1691 auto box = this->box();
1692
1693 return 0.5 * (box.second - box.first).length();
1694 }

References box().

Here is the call graph for this function:

◆ isInside() [1/2]

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

Definition at line 1776 of file geomObjects.cpp.

1777 {
1778
1779 for (auto p: geom::getCornerPoints(3, box))
1780 if (!this->isInside(p))
1781 return false;
1782
1783 return true;
1784 }

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

Here is the call graph for this function:

◆ isInside() [2/2]

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

Definition at line 1701 of file geomObjects.cpp.

1701 {
1702
1703 auto dx = x - d_xBegin;
1704
1705 if (dx.length() < 1.0E-10)
1706 return true;
1707
1708 double dx_dot_xa = dx * d_xa;
1709 if (util::isLess(dx_dot_xa, 0.) or
1710 util::isGreater(dx_dot_xa, d_l))
1711 return false;
1712 else {
1713
1714 // project dx onto cross-section plane of cylinder
1715 auto dx_project = dx - dx_dot_xa * d_xa;
1716
1717 return !util::isGreater(dx_project.length(), d_r + 1.0E-12);
1718 }
1719 }
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 d_l, d_r, d_xa, d_xBegin, util::isGreater(), and util::isLess().

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

Definition at line 1797 of file geomObjects.cpp.

1799 {
1800
1801 return geom::areBoxesNear(this->box(), box, tol, 3);
1802 }
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::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 geom::GeomObject.

Definition at line 1725 of file geomObjects.cpp.

1726 {
1727
1728 auto dx = x - d_xBegin;
1729
1730 if (dx.length() < tol)
1731 return true;
1732
1733 double dx_dot_xa = dx * d_xa;
1734 if (util::isLess(dx_dot_xa, -tol) or
1735 util::isGreater(dx_dot_xa, d_l + tol))
1736 return false;
1737 else {
1738
1739 // project dx onto cross-section plane of cylinder
1740 auto dx_project = dx - dx_dot_xa * d_xa;
1741
1742 return !util::isGreater(dx_project.length(), d_r + tol);
1743 }
1744 }

References d_l, d_r, d_xa, d_xBegin, util::isGreater(), and util::isLess().

Here is the call graph for this function:

◆ isNearBoundary()

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

cons

cons

Reimplemented from geom::GeomObject.

Definition at line 1746 of file geomObjects.cpp.

1748 {
1749
1750 auto dx = x - d_xBegin;
1751
1752 if (dx.length() < tol)
1753 return true;
1754
1755 double dx_dot_xa = dx * d_xa;
1756 if (util::isLess(dx_dot_xa, -tol) or
1757 util::isGreater(dx_dot_xa, tol) or
1758 util::isGreater(dx_dot_xa, d_l + tol) or
1759 util::isLess(dx_dot_xa, d_l - tol))
1760 return false;
1761 else {
1762
1763 // project dx onto cross-section plane of cylinder
1764 auto dx_project = dx - dx_dot_xa * d_xa;
1765
1766 return !(util::isLess(dx_project.length(), d_r - tol) or
1767 util::isGreater(dx_project.length(), d_r + tol));
1768 }
1769 }

References d_l, d_r, d_xa, d_xBegin, util::isGreater(), and util::isLess().

Referenced by doesIntersect().

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

◆ isOutside() [1/2]

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

Definition at line 1786 of file geomObjects.cpp.

1787 {
1788
1789 bool intersect = false;
1790 for (auto p: geom::getCornerPoints(3, box))
1791 if (!intersect)
1792 intersect = this->isInside(p);
1793
1794 return !intersect;
1795 }

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

Here is the call graph for this function:

◆ isOutside() [2/2]

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

Definition at line 1721 of file geomObjects.cpp.

1721 {
1722 return !isInside(x);
1723 }

References isInside().

Here is the call graph for this function:

◆ operator=()

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

Assignment operator.

Parameters
otherObject to copy from
Returns
Reference to this object

Definition at line 3225 of file geomObjects.h.

3225 {
3226 if (this != &other) {
3227 // Copy base class members
3228 d_tags = other.d_tags;
3229
3230 // Copy member variables
3231 d_xBegin = other.d_xBegin;
3232 d_xa = other.d_xa;
3233 d_r = other.d_r;
3234 d_l = other.d_l;
3235 d_x = other.d_x;
3236 }
3237 return *this;
3238 }
double d_x
the x coordinate
Definition point.h:33

References d_l, d_r, geom::GeomObject::d_tags, d_x, d_xa, and d_xBegin.

◆ print() [1/2]

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

Prints the information about the object.

Reimplemented from geom::GeomObject.

Definition at line 3369 of file geomObjects.h.

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

Definition at line 3362 of file geomObjects.h.

3362 {
3363 std::cout << printStr(nt, lvl);
3364 };
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::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 geom::GeomObject.

Definition at line 1816 of file geomObjects.cpp.

1816 {
1817
1818 auto tabS = util::io::getTabS(nt);
1819
1820 std::ostringstream oss;
1821
1822 oss << tabS << "------- Cylinder --------" << std::endl << std::endl;
1823 oss << tabS << "Name = " << d_name << std::endl;
1824 oss << tabS << "Center = " << d_xBegin.printStr(0, lvl) << std::endl;
1825 oss << tabS << "Axis = " << d_xa.printStr(0, lvl) << std::endl;
1826 oss << tabS << "Radius = " << d_r << std::endl;
1827 oss << tabS << "Center = " << d_x.printStr(0, 0) << std::endl;
1828
1829 if (lvl > 0)
1830 oss << tabS << "Bounding box: "
1831 << util::io::printBoxStr(box(0.), nt + 1);
1832
1833 if (lvl == 0)
1834 oss << std::endl;
1835
1836 return oss.str();
1837 }
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(int nt=0, int lvl=0) const
Returns the string containing printable information about the object.
Definition point.h:94

References box(), geom::GeomObject::d_name, d_r, d_x, d_xa, d_xBegin, util::io::getTabS(), util::io::printBoxStr(), 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::Cylinder::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 3240 of file geomObjects.h.

3241 {
3242 // Scale the dimensions
3243 d_r *= scale;
3244 d_l *= scale;
3245
3246 const util::Point c0 = d_x;
3247 d_xBegin = mapSimilarity(d_xBegin, c0, translation, scale, angle, axis, rotationPoint);
3248 d_xa = util::rotate(d_xa, angle, axis);
3249 d_x = mapSimilarity(c0, c0, translation, scale, angle, axis, rotationPoint);
3250 }
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
util::Point rotate(const util::Point &p, const double &theta, const util::Point &axis)
Returns the vector after rotating by desired angle.

References d_l, d_r, d_x, d_xa, d_xBegin, geom::mapSimilarity(), and util::rotate().

Here is the call graph for this function:

◆ volume()

double geom::Cylinder::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 1662 of file geomObjects.cpp.

1662 {
1663 return M_PI * d_r * d_r * d_l;
1664 }

References d_l, and d_r.

Field Documentation

◆ d_l

double geom::Cylinder::d_l

◆ d_r

double geom::Cylinder::d_r

◆ d_x

util::Point geom::Cylinder::d_x

Center.

Definition at line 3142 of file geomObjects.h.

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

◆ d_xa

util::Point geom::Cylinder::d_xa

Axis of cylinder (unit vector)

Definition at line 3148 of file geomObjects.h.

Referenced by box(), mesh_gen::buildCylinderOcc(), isInside(), isNear(), isNearBoundary(), operator=(), printStr(), and transform().

◆ d_xBegin

util::Point geom::Cylinder::d_xBegin

Center point of cross-section at the beginning.

Definition at line 3145 of file geomObjects.h.

Referenced by box(), mesh_gen::buildCylinderOcc(), isInside(), isNear(), isNearBoundary(), operator=(), printStr(), and transform().


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