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

Defines circle. More...

#include <geomObjects.h>

Inheritance diagram for util::geometry::Circle:
Collaboration diagram for util::geometry::Circle:

Public Member Functions

 Circle ()
 Constructor.
 
 Circle (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 circle.

Definition at line 1906 of file geomObjects.h.

Constructor & Destructor Documentation

◆ Circle() [1/2]

util::geometry::Circle::Circle ( )
inline

Constructor.

Definition at line 1912 of file geomObjects.h.

1913 : GeomObject("circle", ""),
1914 d_x(util::Point()),
1915 d_r(0.) {};
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

◆ Circle() [2/2]

util::geometry::Circle::Circle ( 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 1924 of file geomObjects.h.

1926 : GeomObject("circle", description),
1927 d_x(x),
1928 d_r(r) {};

Member Function Documentation

◆ boundingRadius()

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

1226 {
1227
1228 return d_r;
1229 }

◆ box() [1/2]

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

1207 {
1208
1209 return box(0.);
1210 }
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::Circle::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 1212 of file geomObjects.cpp.

1213 {
1214 double r = d_r + tol;
1215 return {
1216 util::Point(d_x.d_x - r, d_x.d_y - r, 0.),
1217 util::Point(d_x.d_x + r, d_x.d_y + r, 0.)
1218 };
1219 }
double d_y
the y coordinate
Definition point.h:36
double d_x
the x coordinate
Definition point.h:33

◆ center()

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

Computes the center of object.

Returns
Point Coordinates of center

Reimplemented from util::geometry::GeomObject.

Definition at line 1203 of file geomObjects.cpp.

1203 {
1204 return d_x;
1205 }

◆ doesIntersect() [1/2]

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

1322 {
1323
1324 // need to check all four corner points
1325 for (auto p: util::getCornerPoints(2, box))
1326 if (this->isInside(p))
1327 return true;
1328
1329 return false;
1330 }
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::Circle::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 1264 of file geomObjects.cpp.

1264 {
1265
1266 return isNearBoundary(x, 1.0E-8, false);
1267 }
bool isNearBoundary(const util::Point &x, const double &tol, const bool &within) const override
cons

◆ inscribedRadius()

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

1221 {
1222
1223 return d_r;
1224 }

◆ isInside() [1/2]

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

1270 {
1271
1272 for (auto p: util::getCornerPoints(2, box))
1273 if (!this->isInside(p))
1274 return false;
1275
1276 return true;
1277 }

References util::getCornerPoints().

Here is the call graph for this function:

◆ isInside() [2/2]

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

1231 {
1232
1233 return util::isLess(d_x.dist(x), d_r + 1.0E-12);
1234 }
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::Circle::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 1290 of file geomObjects.cpp.

1292 {
1293
1294 if (this->isInside(box))
1295 return true;
1296
1297 // get corner points of box
1298 auto cp = getCornerPoints(2, box);
1299
1300 for (auto p: cp) {
1301
1302 // check the distance of corner point with the center
1303 auto dx = p - d_x;
1304 if (util::isLess(dx.length(), d_r + tol))
1305 return true;
1306 }
1307
1308 // check center to center distance
1309 auto dxc = util::getCenter(2, box) - d_x;
1310
1311 // check wrt inscribed circle
1312 auto r = util::inscribedRadiusInBox(2, box);
1313 if (util::isLess(dxc.length(), d_r + r + tol))
1314 return true;
1315
1316 // check wrt circumscribed circle
1318 return util::isLess(dxc.length(), d_r + r + tol);
1319 }
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::Circle::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 1240 of file geomObjects.cpp.

1241 {
1242
1243 // translate to origin
1244 auto x0 = x - d_x;
1245
1246 return util::isLess(x0.length(), d_r + tol);
1247 }

References util::isLess().

Here is the call graph for this function:

◆ isNearBoundary()

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

cons

cons

Reimplemented from util::geometry::GeomObject.

Definition at line 1249 of file geomObjects.cpp.

1251 {
1252
1253 // check if particle is within the tolerance distance
1254 if (!isNear(x, within ? 0. : tol))
1255 return false;
1256
1257 // check if it is close enough to circumference
1258 auto x0 = x - d_x;
1259
1260 return util::isLess(x0.length(), d_r + tol) ||
1261 util::isLess(x0.length(), d_r - tol);
1262 }
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::Circle::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 1279 of file geomObjects.cpp.

1280 {
1281
1282 bool intersect = false;
1283 for (auto p: util::getCornerPoints(2, box))
1284 if (!intersect)
1285 intersect = this->isInside(p);
1286
1287 return !intersect;
1288 }

References util::getCornerPoints().

Here is the call graph for this function:

◆ isOutside() [2/2]

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

1236 {
1237 return !isInside(x);
1238 }

◆ print() [1/2]

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

Prints the information about the object.

Reimplemented from util::geometry::GeomObject.

Definition at line 2047 of file geomObjects.h.

2047{ 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::Circle::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 2040 of file geomObjects.h.

2040 {
2041 std::cout << printStr(nt, lvl);
2042 };
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::Circle::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 1332 of file geomObjects.cpp.

1332 {
1333
1334 auto tabS = util::io::getTabS(nt);
1335
1336 std::ostringstream oss;
1337
1338 oss << tabS << "------- Circle --------" << std::endl << std::endl;
1339 oss << tabS << "Name = " << d_name << std::endl;
1340 oss << tabS << "Center = " << d_x.printStr(0, lvl) << std::endl;
1341 oss << tabS << "Radius = " << d_r << std::endl;
1342
1343 if (lvl > 0)
1344 oss << tabS << "Bounding box: "
1345 << util::io::printBoxStr(box(0.), nt + 1);
1346
1347 if (lvl == 0)
1348 oss << std::endl;
1349
1350 return oss.str();
1351 }
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::Circle::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 1199 of file geomObjects.cpp.

1199 {
1200 return M_PI * d_r * d_r;
1201 }

Field Documentation

◆ d_r

double util::geometry::Circle::d_r

Radius.

Definition at line 2053 of file geomObjects.h.

◆ d_x

util::Point util::geometry::Circle::d_x

Center.

Definition at line 2050 of file geomObjects.h.


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