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

Defines sphere. More...

#include <geomObjects.h>

Inheritance diagram for util::geometry::Sphere:
Collaboration diagram for util::geometry::Sphere:

Public Member Functions

 Sphere ()
 Constructor.
 
 Sphere (double r, util::Point x=util::Point(), 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.
 
double d_r
 Radius.
 
- 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 sphere.

Definition at line 2059 of file geomObjects.h.

Constructor & Destructor Documentation

◆ Sphere() [1/2]

util::geometry::Sphere::Sphere ( )
inline

Constructor.

Definition at line 2065 of file geomObjects.h.

2066 : GeomObject("sphere", ""),
2067 d_x(util::Point()),
2068 d_r(0.) {};
GeomObject(std::string name="", std::string description="")
Constructor.
Definition geomObjects.h:39
util::Point d_x
Center.
A structure to represent 3d vectors.
Definition point.h:30

◆ Sphere() [2/2]

util::geometry::Sphere::Sphere ( double  r,
util::Point  x = util::Point(),
std::string  description = "" 
)
inline

Constructor.

Parameters
rRadius
xCenter
descriptionDescription of object (e.g., further classification or any tag)

Definition at line 2077 of file geomObjects.h.

2079 : GeomObject("sphere", description),
2080 d_x(x),
2081 d_r(r) {};

Member Function Documentation

◆ boundingRadius()

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

1569 {
1570
1571 return d_r;
1572 }

◆ box() [1/2]

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

1549 {
1550
1551 return box(0.);
1552 }
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::Sphere::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 1554 of file geomObjects.cpp.

1555 {
1556 double r = d_r + tol;
1557
1558 return {
1559 util::Point(d_x.d_x - r, d_x.d_y - r, d_x.d_z - r),
1560 util::Point(d_x.d_x + r, d_x.d_y + r, d_x.d_z + r)
1561 };
1562 }
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

◆ center()

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

Computes the center of object.

Returns
Point Coordinates of center

Reimplemented from util::geometry::GeomObject.

Definition at line 1545 of file geomObjects.cpp.

1545 {
1546 return d_x;
1547 }

◆ doesIntersect() [1/2]

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

1665 {
1666
1667 // need to check all four corner points
1668 for (auto p: util::getCornerPoints(3, box))
1669 if (this->isInside(p))
1670 return true;
1671
1672 return false;
1673 }
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::Sphere::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 1607 of file geomObjects.cpp.

1607 {
1608
1609 return isNearBoundary(x, 1.0E-8, false);
1610 }
bool isNearBoundary(const util::Point &x, const double &tol, const bool &within) const override
cons

◆ inscribedRadius()

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

1564 {
1565
1566 return d_r;
1567 }

◆ isInside() [1/2]

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

1613 {
1614
1615 for (auto p: util::getCornerPoints(3, box))
1616 if (!this->isInside(p))
1617 return false;
1618
1619 return true;
1620 }

References util::getCornerPoints().

Here is the call graph for this function:

◆ isInside() [2/2]

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

1574 {
1575
1576 return util::isLess(d_x.dist(x), d_r + 1.0E-12);
1577 }
bool isLess(const double &a, const double &b)
Returns true if a < b.
Definition function.cpp:20
double dist(const Point &b) const
Computes the distance between a given point from this point.
Definition point.h:140

References util::isLess().

Here is the call graph for this function:

◆ isNear() [1/2]

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

1635 {
1636
1637 if (this->isInside(box))
1638 return true;
1639
1640 // get corner points of box
1641 auto cp = getCornerPoints(3, box);
1642
1643 for (auto p: cp) {
1644
1645 // check the distance of corner point with the center
1646 auto dx = p - d_x;
1647 if (util::isLess(dx.length(), d_r + tol))
1648 return true;
1649 }
1650
1651 // check center to center distance
1652 auto dxc = util::getCenter(3, box) - d_x;
1653
1654 // check wrt inscribed circle
1655 auto r = util::inscribedRadiusInBox(3, box);
1656 if (util::isLess(dxc.length(), d_r + r + tol))
1657 return true;
1658
1659 // check wrt circumscribed circle
1661 return util::isLess(dxc.length(), d_r + r + tol);
1662 }
util::Point getCenter(size_t dim, const std::pair< util::Point, util::Point > &box)
Returns center point.
Definition geom.cpp:91
double inscribedRadiusInBox(size_t dim, const std::pair< util::Point, util::Point > &box)
Computes the radius of biggest circle/sphere completely within the object.
Definition geom.cpp:183
double circumscribedRadiusInBox(size_t dim, const std::pair< util::Point, util::Point > &box)
Computes the radius of smallest circle/sphere which can have the box inside.
Definition geom.cpp:208

References util::circumscribedRadiusInBox(), util::getCenter(), util::getCornerPoints(), util::inscribedRadiusInBox(), and util::isLess().

Here is the call graph for this function:

◆ isNear() [2/2]

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

1584 {
1585
1586 // translate to origin
1587 auto x0 = x - d_x;
1588
1589 return util::isLess(x0.length(), d_r + tol);
1590 }

References util::isLess().

Here is the call graph for this function:

◆ isNearBoundary()

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

cons

cons

Reimplemented from util::geometry::GeomObject.

Definition at line 1592 of file geomObjects.cpp.

1594 {
1595
1596 // check if particle is within the tolerance distance
1597 if (!isNear(x, within ? 0. : tol))
1598 return false;
1599
1600 // check if it is close enough to circumference
1601 auto x0 = x - d_x;
1602
1603 return util::isLess(x0.length(), d_r + tol) ||
1604 util::isLess(x0.length(), d_r - tol);
1605 }
bool isNear(const util::Point &x, const double &tol) const override
Checks if point is within given distance of this object.

References util::isLess().

Here is the call graph for this function:

◆ isOutside() [1/2]

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

1623 {
1624
1625 bool intersect = false;
1626 for (auto p: util::getCornerPoints(3, box))
1627 if (!intersect)
1628 intersect = this->isInside(p);
1629
1630 return !intersect;
1631 }

References util::getCornerPoints().

Here is the call graph for this function:

◆ isOutside() [2/2]

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

1579 {
1580 return !isInside(x);
1581 }

◆ print() [1/2]

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

Prints the information about the object.

Reimplemented from util::geometry::GeomObject.

Definition at line 2200 of file geomObjects.h.

2200{ 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::Sphere::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 2193 of file geomObjects.h.

2193 {
2194 std::cout << printStr(nt, lvl);
2195 };
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::Sphere::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 1675 of file geomObjects.cpp.

1675 {
1676
1677 auto tabS = util::io::getTabS(nt);
1678
1679 std::ostringstream oss;
1680
1681 oss << tabS << "------- Sphere --------" << std::endl << std::endl;
1682 oss << tabS << "Name = " << d_name << std::endl;
1683 oss << tabS << "Center = " << d_x.printStr(0, lvl) << std::endl;
1684 oss << tabS << "Radius = " << d_r << std::endl;
1685
1686 if (lvl > 0)
1687 oss << tabS << "Bounding box: "
1688 << util::io::printBoxStr(box(0.), nt + 1);
1689
1690 if (lvl == 0)
1691 oss << std::endl;
1692
1693 return oss.str();
1694 }
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::Sphere::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 1541 of file geomObjects.cpp.

1541 {
1542 return 4. * M_PI * d_r * d_r * d_r / 3.;
1543 }

Field Documentation

◆ d_r

double util::geometry::Sphere::d_r

Radius.

Definition at line 2206 of file geomObjects.h.

◆ d_x

util::Point util::geometry::Sphere::d_x

Center.

Definition at line 2203 of file geomObjects.h.


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