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

Defines Hexagon. More...

#include <geomObjects.h>

Inheritance diagram for util::geometry::Hexagon:
Collaboration diagram for util::geometry::Hexagon:

Public Member Functions

 Hexagon ()
 Constructor.
 
 Hexagon (double r, util::Point x=util::Point(0., 0., 0.), util::Point a=util::Point(1., 0., 0.), 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

TODO implement methods robustly

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_r
 Distance between center and the farthest vertex of hexagon.
 
util::Point d_a
 Axis: defined as the vector pointing from center to the first vertex.
 
- 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 Hexagon.

Definition at line 1027 of file geomObjects.h.

Constructor & Destructor Documentation

◆ Hexagon() [1/2]

util::geometry::Hexagon::Hexagon ( )
inline

Constructor.

Definition at line 1033 of file geomObjects.h.

1034 : GeomObject("hexagon", ""),
1035 d_r(0.),
1036 d_a(util::Point(1., 0., 0.)),
1037 d_x(util::Point()),
1038 d_vertices(std::vector<util::Point>(6, util::Point())) {};
GeomObject(std::string name="", std::string description="")
Constructor.
Definition geomObjects.h:39
std::vector< util::Point > d_vertices
Vertices.
double d_r
Distance between center and the farthest vertex of hexagon.
util::Point d_x
Center.
util::Point d_a
Axis: defined as the vector pointing from center to the first vertex.
A structure to represent 3d vectors.
Definition point.h:30

◆ Hexagon() [2/2]

util::geometry::Hexagon::Hexagon ( double  r,
util::Point  x = util::Point(0., 0., 0.),
util::Point  a = util::Point(1., 0., 0.),
std::string  description = "" 
)
inline

Constructor.

Parameters
rRadius (distance between center and one of the vertices)
xCenter point
aAxis vector that will be rotated and scaled by r to obtain coordinates of vertices of hexagon
descriptionDescription of object (e.g., further classification or any tag)

Definition at line 1048 of file geomObjects.h.

1051 : GeomObject("hexagon", ""),
1052 d_r(r),
1053 d_a(a),
1054 d_x(x),
1055 d_vertices(std::vector<util::Point>(6, util::Point())) {
1056
1057 // generate vertices
1058 auto rotate_axis = util::Point(0., 0., 1.); // z-axis
1059 for (int i = 0; i < 6; i++) {
1060 d_vertices[i] = d_x + d_r * util::rotate(
1061 d_a, i * M_PI / 3., rotate_axis);
1062 }
1063 };
util::Point rotate(const util::Point &p, const double &theta, const util::Point &axis)
Returns the vector after rotating by desired angle.

References d_a, d_r, d_vertices, d_x, and util::rotate().

Here is the call graph for this function:

Member Function Documentation

◆ boundingRadius()

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

647 {
648
649 return d_r;
650 }

◆ box() [1/2]

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

629 {
630
631 return box(0.);
632 }
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::Hexagon::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 634 of file geomObjects.cpp.

635 {
636
637 auto p1 = d_x - util::Point(d_r + tol, d_r + tol, d_x[2] + tol);
638 auto p2 = d_x + util::Point(d_r + tol, d_r + tol, d_x[2] + tol);
639 return {p1, p2};
640 }

◆ center()

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

Computes the center of object.

Returns
Point Coordinates of center

Reimplemented from util::geometry::GeomObject.

Definition at line 625 of file geomObjects.cpp.

625 {
626 return d_x;
627 }

◆ doesIntersect() [1/2]

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

723 {
724
725 // need to check all four corner points
726 for (auto p: util::getCornerPoints(2, box))
727 if (this->isInside(p))
728 return true;
729
730 return false;
731 }
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::Hexagon::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 689 of file geomObjects.cpp.

689 {
690
691 return isNearBoundary(x, 1.0E-8, false);
692 }
bool isNearBoundary(const util::Point &x, const double &tol, const bool &within) const override
cons

◆ inscribedRadius()

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

642 {
643
644 return d_r * 0.5 * std::sqrt(3.);
645 }

◆ isInside() [1/2]

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

695 {
696
697 for (auto p: util::getCornerPoints(2, box))
698 if (!this->isInside(p))
699 return false;
700
701 return true;
702 }

References util::getCornerPoints().

Here is the call graph for this function:

◆ isInside() [2/2]

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

652 {
653
654 if ((x - d_x).length() > d_r)
655 return false;
656
657 if ((x - d_x).length() < inscribedRadius())
658 return true;
659
660 return false;
661 }
double inscribedRadius() const override
Computes the radius of biggest circle/sphere completely within the object.

◆ isNear() [1/2]

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

717 {
718
719 return util::areBoxesNear(this->box(), box, tol, 2);
720 }
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::Hexagon::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 667 of file geomObjects.cpp.

668 {
669
670 // get a bigger box containing this object
671 auto bbox = box(tol);
672
673 return util::isPointInsideBox(x, 2, bbox);
674 }
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::Hexagon::isNearBoundary ( const util::Point x,
const double &  tol,
const bool &  within 
) const
overridevirtual

cons

cons

Reimplemented from util::geometry::GeomObject.

Definition at line 676 of file geomObjects.cpp.

678 {
679
680 if ((x - d_x).length() > d_r + tol)
681 return false;
682
683 if ((x - d_x).length() < inscribedRadius() - tol)
684 return false;
685
686 return true;
687 }

◆ isOutside() [1/2]

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

705 {
706
707 bool intersect = false;
708 for (auto p: util::getCornerPoints(2, box))
709 if (!intersect)
710 intersect = this->isInside(p);
711
712 return !intersect;
713 }

References util::getCornerPoints().

Here is the call graph for this function:

◆ isOutside() [2/2]

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

663 {
664 return !isInside(x);
665 }

◆ print() [1/2]

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

Prints the information about the object.

Reimplemented from util::geometry::GeomObject.

Definition at line 1184 of file geomObjects.h.

1184{ 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::Hexagon::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 1177 of file geomObjects.h.

1177 {
1178 std::cout << printStr(nt, lvl);
1179 };
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::Hexagon::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 733 of file geomObjects.cpp.

733 {
734
735 auto tabS = util::io::getTabS(nt);
736
737 std::ostringstream oss;
738
739 oss << tabS << "------- Hexagon --------" << std::endl << std::endl;
740 oss << tabS << "Name = " << d_name << std::endl;
741 oss << tabS << "Radius = " << d_r << std::endl;
742 oss << tabS << "Center = " << d_x.printStr(0, lvl) << std::endl;
743 oss << tabS << "Axis = " << d_a.printStr(0, lvl) << std::endl;
744 oss << tabS << "Vertices = " << util::io::printStr(d_vertices, lvl) <<
745 std::endl;
746 oss << std::endl;
747
748 if (lvl == 0)
749 oss << std::endl;
750
751 return oss.str();
752 }
const std::string d_name
name of object
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(), 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::Hexagon::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 619 of file geomObjects.cpp.

619 {
620 // https://en.wikipedia.org/wiki/Hexagon
621 double r_small = this->inscribedRadius();
622 return 2. * std::sqrt(3.) * r_small * r_small;
623 }

Field Documentation

◆ d_a

util::Point util::geometry::Hexagon::d_a

Axis: defined as the vector pointing from center to the first vertex.

                   +              +


               +           o           +
                           x            v1

                   +              +

Axis is a vector from x to v1

Definition at line 1208 of file geomObjects.h.

Referenced by Hexagon().

◆ d_r

double util::geometry::Hexagon::d_r

Distance between center and the farthest vertex of hexagon.

Definition at line 1193 of file geomObjects.h.

Referenced by Hexagon().

◆ d_vertices

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

Vertices.

Definition at line 1187 of file geomObjects.h.

Referenced by Hexagon().

◆ d_x

util::Point util::geometry::Hexagon::d_x

Center.

Definition at line 1190 of file geomObjects.h.

Referenced by Hexagon().


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