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

Defines sphere. More...

#include <geomObjects.h>

Inheritance diagram for geom::Sphere:
Collaboration diagram for geom::Sphere:

Public Member Functions

 Sphere ()
 Constructor.
 
 Sphere (double r, util::Point x=util::Point(), std::string description="")
 Constructor.
 
 Sphere (const Sphere &other)
 Copy constructor.
 
Sphereoperator= (const Sphere &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.
 
double d_r
 Radius.
 
- 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 sphere.

Definition at line 2839 of file geomObjects.h.

Constructor & Destructor Documentation

◆ Sphere() [1/3]

geom::Sphere::Sphere ( )
inline

Constructor.

Definition at line 2851 of file geomObjects.h.

2852 : GeomObject("sphere", ""),
2853 d_x(util::Point()),
2854 d_r(0.) {
2855 };
GeomObject(std::string name="", std::string description="")
Constructor.
double d_r
Radius.
util::Point d_x
Center.
A structure to represent 3d vectors.
Definition point.h:30

◆ Sphere() [2/3]

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

2866 : GeomObject("sphere", description),
2867 d_x(x),
2868 d_r(r) {
2869 };

◆ Sphere() [3/3]

geom::Sphere::Sphere ( const Sphere other)
inline

Copy constructor.

Parameters
otherObject to copy from

Definition at line 2875 of file geomObjects.h.

2876 : GeomObject(other.d_name, other.d_description),
2877 d_x(other.d_x),
2878 d_r(other.d_r) {
2879 d_tags = other.d_tags;
2880 }
std::vector< std::string > d_tags
Tags/attributes about the object.

References geom::GeomObject::d_tags.

Member Function Documentation

◆ boundingRadius()

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

Definition at line 1873 of file geomObjects.cpp.

1873 {
1874
1875 return d_r;
1876 }

References d_r.

◆ box() [1/2]

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

Definition at line 1853 of file geomObjects.cpp.

1853 {
1854
1855 return box(0.);
1856 }
std::pair< util::Point, util::Point > box() const override
Computes the bounding box of object.

References box().

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

Definition at line 1858 of file geomObjects.cpp.

1859 {
1860 double r = d_r + tol;
1861
1862 return {
1863 util::Point(d_x.d_x - r, d_x.d_y - r, d_x.d_z - r),
1864 util::Point(d_x.d_x + r, d_x.d_y + r, d_x.d_z + r)
1865 };
1866 }
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_r, d_x, util::Point::d_x, util::Point::d_y, and util::Point::d_z.

◆ center()

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

Computes the center of object.

Returns
Point Coordinates of center

Reimplemented from geom::GeomObject.

Definition at line 1849 of file geomObjects.cpp.

1849 {
1850 return d_x;
1851 }

References d_x.

◆ doesIntersect() [1/2]

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

Definition at line 1968 of file geomObjects.cpp.

1969 {
1970
1971 // need to check all four corner points
1972 for (auto p: geom::getCornerPoints(3, box))
1973 if (this->isInside(p))
1974 return true;
1975
1976 return false;
1977 }
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::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 geom::GeomObject.

Definition at line 1911 of file geomObjects.cpp.

1911 {
1912
1913 return isNearBoundary(x, 1.0E-8, false);
1914 }
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::Sphere::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 1868 of file geomObjects.cpp.

1868 {
1869
1870 return d_r;
1871 }

References d_r.

◆ isInside() [1/2]

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

Definition at line 1916 of file geomObjects.cpp.

1917 {
1918
1919 for (auto p: geom::getCornerPoints(3, box))
1920 if (!this->isInside(p))
1921 return false;
1922
1923 return true;
1924 }

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

Here is the call graph for this function:

◆ isInside() [2/2]

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

Definition at line 1878 of file geomObjects.cpp.

1878 {
1879
1880 return util::isLess(d_x.dist(x), d_r + 1.0E-12);
1881 }
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:146

References d_r, d_x, util::Point::dist(), and util::isLess().

Referenced by doesIntersect(), isInside(), isNear(), isOutside(), and isOutside().

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

◆ isNear() [1/2]

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

Definition at line 1937 of file geomObjects.cpp.

1939 {
1940
1941 if (this->isInside(box))
1942 return true;
1943
1944 // get corner points of box
1945 auto cp = geom::getCornerPoints(3, box);
1946
1947 for (auto p: cp) {
1948
1949 // check the distance of corner point with the center
1950 auto dx = p - d_x;
1951 if (util::isLess(dx.length(), d_r + tol))
1952 return true;
1953 }
1954
1955 // check center to center distance
1956 auto dxc = geom::getCenter(3, box) - d_x;
1957
1958 // check wrt inscribed circle
1959 auto r = geom::inscribedRadiusInBox(3, box);
1960 if (util::isLess(dxc.length(), d_r + r + tol))
1961 return true;
1962
1963 // check wrt circumscribed circle
1965 return util::isLess(dxc.length(), d_r + r + tol);
1966 }
util::Point getCenter(size_t dim, const std::pair< util::Point, util::Point > &box)
Returns center point.
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.
double inscribedRadiusInBox(size_t dim, const std::pair< util::Point, util::Point > &box)
Computes the radius of biggest circle/sphere completely within the object.

References box(), geom::circumscribedRadiusInBox(), d_r, d_x, geom::getCenter(), geom::getCornerPoints(), geom::inscribedRadiusInBox(), isInside(), and util::isLess().

Here is the call graph for this function:

◆ isNear() [2/2]

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

Definition at line 1887 of file geomObjects.cpp.

1888 {
1889
1890 // translate to origin
1891 auto x0 = x - d_x;
1892
1893 return util::isLess(x0.length(), d_r + tol);
1894 }

References d_r, d_x, and util::isLess().

Referenced by isNearBoundary().

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

◆ isNearBoundary()

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

cons

cons

Reimplemented from geom::GeomObject.

Definition at line 1896 of file geomObjects.cpp.

1898 {
1899
1900 // check if particle is within the tolerance distance
1901 if (!isNear(x, within ? 0. : tol))
1902 return false;
1903
1904 // check if it is close enough to circumference
1905 auto x0 = x - d_x;
1906
1907 return util::isLess(x0.length(), d_r + tol) ||
1908 util::isLess(x0.length(), d_r - tol);
1909 }
bool isNear(const util::Point &x, const double &tol) const override
Checks if point is within given distance of this object.

References d_r, d_x, 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::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 geom::GeomObject.

Definition at line 1926 of file geomObjects.cpp.

1927 {
1928
1929 bool intersect = false;
1930 for (auto p: geom::getCornerPoints(3, box))
1931 if (!intersect)
1932 intersect = this->isInside(p);
1933
1934 return !intersect;
1935 }

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

Here is the call graph for this function:

◆ isOutside() [2/2]

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

Definition at line 1883 of file geomObjects.cpp.

1883 {
1884 return !isInside(x);
1885 }

References isInside().

Here is the call graph for this function:

◆ operator=()

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

Assignment operator.

Parameters
otherObject to copy from
Returns
Reference to this object

Definition at line 2887 of file geomObjects.h.

2887 {
2888 if (this != &other) {
2889 // Copy base class members
2890 d_tags = other.d_tags;
2891
2892 // Copy member variables
2893 d_x = other.d_x;
2894 d_r = other.d_r;
2895 }
2896 return *this;
2897 }

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

◆ print() [1/2]

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

Prints the information about the object.

Reimplemented from geom::GeomObject.

Definition at line 3023 of file geomObjects.h.

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

Definition at line 3016 of file geomObjects.h.

3016 {
3017 std::cout << printStr(nt, lvl);
3018 };
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::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 geom::GeomObject.

Definition at line 1979 of file geomObjects.cpp.

1979 {
1980
1981 auto tabS = util::io::getTabS(nt);
1982
1983 std::ostringstream oss;
1984
1985 oss << tabS << "------- Sphere --------" << std::endl << std::endl;
1986 oss << tabS << "Name = " << d_name << std::endl;
1987 oss << tabS << "Center = " << d_x.printStr(0, lvl) << std::endl;
1988 oss << tabS << "Radius = " << d_r << std::endl;
1989
1990 if (lvl > 0)
1991 oss << tabS << "Bounding box: "
1992 << util::io::printBoxStr(box(0.), nt + 1);
1993
1994 if (lvl == 0)
1995 oss << std::endl;
1996
1997 return oss.str();
1998 }
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, 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::Sphere::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 2899 of file geomObjects.h.

2900 {
2901 const util::Point c0 = d_x;
2902 d_r *= scale;
2903 d_x = mapSimilarity(c0, c0, translation, scale, angle, axis, rotationPoint);
2904 }
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_r, d_x, and geom::mapSimilarity().

Here is the call graph for this function:

◆ volume()

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

1845 {
1846 return 4. * M_PI * d_r * d_r * d_r / 3.;
1847 }

References d_r.

Field Documentation

◆ d_r

◆ d_x


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