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

Defines Square. More...

#include <geomObjects.h>

Inheritance diagram for util::geometry::Square:
Collaboration diagram for util::geometry::Square:

Public Member Functions

 Square ()
 Constructor.
 
 Square (double L, util::Point x=util::Point(), std::string description="")
 Constructor.
 
 Square (util::Point x1, util::Point x2, 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

std::vector< util::Pointd_vertices
 Vertices.
 
util::Point d_x
 Center.
 
double d_L
 Edge length of a square.
 
double d_r
 Radius of bounding circle.
 
- 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 Square.

Definition at line 641 of file geomObjects.h.

Constructor & Destructor Documentation

◆ Square() [1/3]

util::geometry::Square::Square ( )
inline

Constructor.

Definition at line 647 of file geomObjects.h.

648 : GeomObject("square", ""),
649 d_L(0.),
650 d_r(0.),
651 d_x(util::Point()),
653 util::Point(), util::Point()}) {};
GeomObject(std::string name="", std::string description="")
Constructor.
Definition geomObjects.h:39
std::vector< util::Point > d_vertices
Vertices.
util::Point d_x
Center.
double d_L
Edge length of a square.
double d_r
Radius of bounding circle.
A structure to represent 3d vectors.
Definition point.h:30

◆ Square() [2/3]

util::geometry::Square::Square ( double  L,
util::Point  x = util::Point(),
std::string  description = "" 
)
inline

Constructor.

Parameters
LLength along x and y-directions (Square)
xCenter point
descriptionDescription of object (e.g., further classification or any tag)

Definition at line 662 of file geomObjects.h.

664 : GeomObject("square", description),
665 d_L(L),
666 d_r(L / std::sqrt(2)),
667 d_x(x),
668 d_vertices({x + util::Point(-0.5 * L, -0.5 * L, 0.),
669 x + util::Point(0.5 * L, -0.5 * L, 0.),
670 x + util::Point(0.5 * L, 0.5 * L, 0.),
671 x + util::Point(-0.5 * L, 0.5 * L, 0.)}) {};

◆ Square() [3/3]

util::geometry::Square::Square ( util::Point  x1,
util::Point  x2,
std::string  description = "" 
)
inline

Constructor.

Parameters
x1Left-bottom corner point
x2Right-top corner point
descriptionDescription of object (e.g., further classification or any tag)

Definition at line 680 of file geomObjects.h.

681 : GeomObject("square", description),
682 d_L((x1 - x2).length() * (1. / std::sqrt(2))),
683 d_r((x1 - x2).length() / 2.),
684 d_x(0.5 * (x1 + x2)) {
685
686 d_vertices.push_back(x1);
687 d_vertices.push_back(util::Point(x1.d_x + d_L, x1.d_y, x1.d_z));
688 d_vertices.push_back(x2);
689 d_vertices.push_back(util::Point(x2.d_x - d_L, x2.d_y, x2.d_z));
690 };
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_L, d_vertices, util::Point::d_x, util::Point::d_y, and util::Point::d_z.

Member Function Documentation

◆ boundingRadius()

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

371 {
372
373 return d_r;
374 }

◆ box() [1/2]

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

353 {
354
355 return box(0.);
356 }
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::Square::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 357 of file geomObjects.cpp.

358 {
359
360 return {util::Point(d_vertices[0].d_x - tol, d_vertices[0].d_y - tol,
361 0.),
362 util::Point(d_vertices[2].d_x + tol, d_vertices[2].d_y + tol,
363 0.)};
364 }

◆ center()

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

Computes the center of object.

Returns
Point Coordinates of center

Reimplemented from util::geometry::GeomObject.

Definition at line 349 of file geomObjects.cpp.

349 {
350 return d_x;
351 }

◆ doesIntersect() [1/2]

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

443 {
444
445 // need to check all four corner points
446 for (auto p : util::getCornerPoints(2, box))
447 if (this->isInside(p))
448 return true;
449
450 return false;
451 }
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::Square::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 410 of file geomObjects.cpp.

410 {
411
412 return isNearBoundary(x, 1.0E-8, false);
413 }
bool isNearBoundary(const util::Point &x, const double &tol, const bool &within) const override
cons

◆ inscribedRadius()

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

366 {
367
368 return 0.5*d_L;
369 }

◆ isInside() [1/2]

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

416 {
417
418 for (auto p : util::getCornerPoints(2, box))
419 if(!this->isInside(p))
420 return false;
421
422 return true;
423 }

References util::getCornerPoints().

Here is the call graph for this function:

◆ isInside() [2/2]

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

376 {
378 }
bool isPointInsideRectangle(util::Point x, double x_min, double x_max, double y_min, double y_max)
Checks if point is inside a rectangle.
Definition geom.cpp:231

References util::isPointInsideRectangle().

Here is the call graph for this function:

◆ isNear() [1/2]

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

437 {
438
439 return util::areBoxesNear(this->box(), box, tol, 2);
440 }
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::Square::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 384 of file geomObjects.cpp.

385 {
386
387 // get a bigger box containing this object
388 auto bbox = box(tol);
389
390 return util::isPointInsideBox(x, 2, bbox);
391 }
bool isPointInsideBox(util::Point x, size_t dim, const std::pair< util::Point, util::Point > &box)
Returns true if point is inside box.
Definition geom.cpp:159

References util::isPointInsideBox().

Here is the call graph for this function:

◆ isNearBoundary()

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

cons

cons

Reimplemented from util::geometry::GeomObject.

Definition at line 393 of file geomObjects.cpp.

395 {
396
397 // check if particle is inside the object
398 if (!isNear(x, within ? 0. : tol))
399 return false;
400
401 bool near_x_edge = util::isLess(std::abs(x.d_x - d_vertices[0].d_x), tol) or
402 util::isLess(std::abs(x.d_x - d_vertices[2].d_x), tol);
403
404 bool near_y_edge = util::isLess(std::abs(x.d_y - d_vertices[0].d_y), tol) or
405 util::isLess(std::abs(x.d_y - d_vertices[2].d_y), tol);
406
407 return near_x_edge || near_y_edge;
408 }
bool isNear(const util::Point &x, const double &tol) const override
Checks if point is within given distance of this object.
bool isLess(const double &a, const double &b)
Returns true if a < b.
Definition function.cpp:20

References util::Point::d_x, util::Point::d_y, and util::isLess().

Here is the call graph for this function:

◆ isOutside() [1/2]

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

426 {
427
428 bool intersect = false;
429 for (auto p : util::getCornerPoints(2, box))
430 if (!intersect)
431 intersect = this->isInside(p);
432
433 return !intersect;
434 }

References util::getCornerPoints().

Here is the call graph for this function:

◆ isOutside() [2/2]

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

380 {
381 return !isInside(x);
382 }

◆ print() [1/2]

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

Prints the information about the object.

Reimplemented from util::geometry::GeomObject.

Definition at line 809 of file geomObjects.h.

809{ 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::Square::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 802 of file geomObjects.h.

802 {
803 std::cout << printStr(nt, lvl);
804 };
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::Square::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 453 of file geomObjects.cpp.

453 {
454
455 auto tabS = util::io::getTabS(nt);
456
457 std::ostringstream oss;
458
459 oss << tabS << "------- Rectangle --------" << std::endl << std::endl;
460 oss << tabS << "Name = " << d_name << std::endl;
461 oss << tabS << "Length = " << d_L << std::endl;
462 oss << tabS << "Bounding radius = " << d_r << std::endl;
463 oss << tabS << "Center = " << d_x.printStr(0, lvl) << std::endl;
464 oss << tabS << "Vertices = " << util::io::printStr(d_vertices, 0) << std::endl;
465 oss << std::endl;
466
467 if (lvl > 0)
468 oss << tabS << "Bounding box: " << util::io::printBoxStr(box(0.), nt + 1);
469
470 if (lvl == 0)
471 oss << std::endl;
472
473 return oss.str();
474 }
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(const T &msg, int nt=print_default_tab)
Returns formatted string for output.
Definition io.h:54
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(), util::io::printBoxStr(), and util::io::printStr().

Referenced by print().

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

◆ volume()

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

345 {
346 return std::pow(d_L, 2);
347 }

Field Documentation

◆ d_L

double util::geometry::Square::d_L

Edge length of a square.

Definition at line 818 of file geomObjects.h.

Referenced by Square().

◆ d_r

double util::geometry::Square::d_r

Radius of bounding circle.

Definition at line 821 of file geomObjects.h.

◆ d_vertices

std::vector<util::Point> util::geometry::Square::d_vertices

Vertices.

Definition at line 812 of file geomObjects.h.

Referenced by Square().

◆ d_x

util::Point util::geometry::Square::d_x

Center.

Definition at line 815 of file geomObjects.h.


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