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

Defines Hexagon. More...

#include <geomObjects.h>

Inheritance diagram for geom::Hexagon:
Collaboration diagram for geom::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.
 
 Hexagon (const Hexagon &other)
 Copy constructor.
 
Hexagonoperator= (const Hexagon &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

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 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

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 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 Hexagon.

Definition at line 1509 of file geomObjects.h.

Constructor & Destructor Documentation

◆ Hexagon() [1/3]

geom::Hexagon::Hexagon ( )
inline

Constructor.

Definition at line 1539 of file geomObjects.h.

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

◆ Hexagon() [2/3]

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

1558 : GeomObject("hexagon", ""),
1559 d_r(r),
1560 d_a(a),
1561 d_x(x),
1562 d_vertices(std::vector<util::Point>(6, util::Point())) {
1563 // generate vertices
1564 auto rotate_axis = util::Point(0., 0., 1.); // z-axis
1565 for (int i = 0; i < 6; i++) {
1566 d_vertices[i] = d_x + d_r * util::rotate(
1567 d_a, i * M_PI / 3., rotate_axis);
1568 }
1569 };
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:

◆ Hexagon() [3/3]

geom::Hexagon::Hexagon ( const Hexagon other)
inline

Copy constructor.

Parameters
otherObject to copy from

Definition at line 1575 of file geomObjects.h.

1576 : GeomObject(other.d_name, other.d_description),
1577 d_r(other.d_r),
1578 d_a(other.d_a),
1579 d_x(other.d_x),
1580 d_vertices(other.d_vertices) {
1581 d_tags = other.d_tags;
1582 }
std::vector< std::string > d_tags
Tags/attributes about the object.

References geom::GeomObject::d_tags.

Member Function Documentation

◆ boundingRadius()

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

Definition at line 796 of file geomObjects.cpp.

796 {
797
798 return d_r;
799 }

References d_r.

◆ box() [1/2]

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

Definition at line 778 of file geomObjects.cpp.

778 {
779
780 return box(0.);
781 }
std::pair< util::Point, util::Point > box() const override
Computes the bounding box of object.

References box().

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

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

Definition at line 783 of file geomObjects.cpp.

784 {
785
786 auto p1 = d_x - util::Point(d_r + tol, d_r + tol, d_x[2] + tol);
787 auto p2 = d_x + util::Point(d_r + tol, d_r + tol, d_x[2] + tol);
788 return {p1, p2};
789 }

References d_r, and d_x.

◆ center()

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

Computes the center of object.

Returns
Point Coordinates of center

Reimplemented from geom::GeomObject.

Definition at line 774 of file geomObjects.cpp.

774 {
775 return d_x;
776 }

References d_x.

◆ doesIntersect() [1/2]

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

Definition at line 871 of file geomObjects.cpp.

872 {
873
874 // need to check all four corner points
875 for (auto p: geom::getCornerPoints(2, box))
876 if (this->isInside(p))
877 return true;
878
879 return false;
880 }
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::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 geom::GeomObject.

Definition at line 838 of file geomObjects.cpp.

838 {
839
840 return isNearBoundary(x, 1.0E-8, false);
841 }
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::Hexagon::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 791 of file geomObjects.cpp.

791 {
792
793 return d_r * 0.5 * std::sqrt(3.);
794 }

References d_r.

Referenced by isInside(), isNearBoundary(), and volume().

Here is the caller graph for this function:

◆ isInside() [1/2]

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

Definition at line 843 of file geomObjects.cpp.

844 {
845
846 for (auto p: geom::getCornerPoints(2, box))
847 if (!this->isInside(p))
848 return false;
849
850 return true;
851 }

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

Here is the call graph for this function:

◆ isInside() [2/2]

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

Definition at line 801 of file geomObjects.cpp.

801 {
802
803 if ((x - d_x).length() > d_r)
804 return false;
805
806 if ((x - d_x).length() < inscribedRadius())
807 return true;
808
809 return false;
810 }
double inscribedRadius() const override
Computes the radius of biggest circle/sphere completely within the object.

References d_r, d_x, and inscribedRadius().

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

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

◆ isNear() [1/2]

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

Definition at line 864 of file geomObjects.cpp.

866 {
867
868 return geom::areBoxesNear(this->box(), box, tol, 2);
869 }
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.

References geom::areBoxesNear(), and box().

Here is the call graph for this function:

◆ isNear() [2/2]

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

Definition at line 816 of file geomObjects.cpp.

817 {
818
819 // get a bigger box containing this object
820 auto bbox = box(tol);
821
822 return geom::isPointInsideBox(x, 2, bbox);
823 }
bool isPointInsideBox(util::Point x, size_t dim, const std::pair< util::Point, util::Point > &box)
Returns true if point is inside box.

References box(), and geom::isPointInsideBox().

Here is the call graph for this function:

◆ isNearBoundary()

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

cons

cons

Reimplemented from geom::GeomObject.

Definition at line 825 of file geomObjects.cpp.

827 {
828
829 if ((x - d_x).length() > d_r + tol)
830 return false;
831
832 if ((x - d_x).length() < inscribedRadius() - tol)
833 return false;
834
835 return true;
836 }

References d_r, d_x, and inscribedRadius().

Referenced by doesIntersect().

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

◆ isOutside() [1/2]

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

Definition at line 853 of file geomObjects.cpp.

854 {
855
856 bool intersect = false;
857 for (auto p: geom::getCornerPoints(2, box))
858 if (!intersect)
859 intersect = this->isInside(p);
860
861 return !intersect;
862 }

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

Here is the call graph for this function:

◆ isOutside() [2/2]

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

Definition at line 812 of file geomObjects.cpp.

812 {
813 return !isInside(x);
814 }

References isInside().

Here is the call graph for this function:

◆ operator=()

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

Assignment operator.

Parameters
otherObject to copy from
Returns
Reference to this object

Definition at line 1589 of file geomObjects.h.

1589 {
1590 if (this != &other) {
1591 // Copy base class members
1592 d_tags = other.d_tags;
1593
1594 // Copy member variables
1595 d_r = other.d_r;
1596 d_a = other.d_a;
1597 d_x = other.d_x;
1598 d_vertices = other.d_vertices;
1599 }
1600 return *this;
1601 }
double d_x
the x coordinate
Definition point.h:33

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

◆ print() [1/2]

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

Prints the information about the object.

Reimplemented from geom::GeomObject.

Definition at line 1735 of file geomObjects.h.

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

Definition at line 1728 of file geomObjects.h.

1728 {
1729 std::cout << printStr(nt, lvl);
1730 };
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::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 geom::GeomObject.

Definition at line 882 of file geomObjects.cpp.

882 {
883
884 auto tabS = util::io::getTabS(nt);
885
886 std::ostringstream oss;
887
888 oss << tabS << "------- Hexagon --------" << std::endl << std::endl;
889 oss << tabS << "Name = " << d_name << std::endl;
890 oss << tabS << "Radius = " << d_r << std::endl;
891 oss << tabS << "Center = " << d_x.printStr(0, lvl) << std::endl;
892 oss << tabS << "Axis = " << d_a.printStr(0, lvl) << std::endl;
893 oss << tabS << "Vertices = " << util::io::printStr(d_vertices, lvl) <<
894 std::endl;
895 oss << std::endl;
896
897 if (lvl == 0)
898 oss << std::endl;
899
900 return oss.str();
901 }
const std::string d_name
name of object
std::string getTabS(int nt)
Returns tab spaces of a given size.
Definition io.h:39
std::string printStr(const T &msg, int nt=print_default_tab)
Returns formatted string for output.
Definition io.h:53
std::string printStr(int nt=0, int lvl=0) const
Returns the string containing printable information about the object.
Definition point.h:94

References d_a, geom::GeomObject::d_name, d_r, d_vertices, d_x, util::io::getTabS(), util::io::printStr(), 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::Hexagon::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 1603 of file geomObjects.h.

1604 {
1605 // Scale the radius
1606 d_r *= scale;
1607
1608 const util::Point c0 = d_x;
1609 for (auto &v : d_vertices) {
1610 v = mapSimilarity(v, c0, translation, scale, angle, axis, rotationPoint);
1611 }
1612 d_x = mapSimilarity(c0, c0, translation, scale, angle, axis, rotationPoint);
1613 d_a = util::rotate(d_a, angle, axis);
1614 }
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_a, d_r, d_vertices, d_x, geom::mapSimilarity(), and util::rotate().

Here is the call graph for this function:

◆ volume()

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

768 {
769 // https://en.wikipedia.org/wiki/Hexagon
770 double r_small = this->inscribedRadius();
771 return 2. * std::sqrt(3.) * r_small * r_small;
772 }

References inscribedRadius().

Here is the call graph for this function:

Field Documentation

◆ d_a

util::Point geom::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 1533 of file geomObjects.h.

Referenced by Hexagon(), operator=(), printStr(), and transform().

◆ d_r

double geom::Hexagon::d_r

Distance between center and the farthest vertex of hexagon.

Definition at line 1518 of file geomObjects.h.

Referenced by boundingRadius(), box(), Hexagon(), inscribedRadius(), isInside(), isNearBoundary(), operator=(), printStr(), and transform().

◆ d_vertices

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

Vertices.

Definition at line 1512 of file geomObjects.h.

Referenced by Hexagon(), operator=(), printStr(), and transform().

◆ d_x

util::Point geom::Hexagon::d_x

Center.

Definition at line 1515 of file geomObjects.h.

Referenced by box(), center(), Hexagon(), isInside(), isNearBoundary(), operator=(), printStr(), and transform().


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