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

Defines Drum2D. More...

#include <geomObjects.h>

Inheritance diagram for geom::Drum2D:
Collaboration diagram for geom::Drum2D:

Public Member Functions

 Drum2D ()
 Constructor.
 
 Drum2D (double r, double w, util::Point x=util::Point(0., 0., 0.), util::Point a=util::Point(1., 0., 0.), std::string description="")
 Constructor.
 
Drum2Doperator= (const Drum2D &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

std::vector< util::Pointd_vertices
 Vertices.
 
util::Point d_x
 Center.
 
double d_w
 Half width of neck.
 
double d_r
 Distance between center and the farthest vertex.
 
util::Point d_a
 Axis: defined as the vector pointing from center to the first vertex v3 v2.
 
- 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 Drum2D.

        v3   o-------------------o   v2
             \                   /
              \                 /
               \               /
          v4    o      +      o v1
               /       c       \
              /                 \
             /                   \
       v5   o---------------------o  v6

w = distance between c and v1 = half-width of neck r = distance between c and v2 theta = pi/3 = angle between c-v2 and c-v1 a = axis = unit vector from c to v1

Definition at line 1757 of file geomObjects.h.

Constructor & Destructor Documentation

◆ Drum2D() [1/2]

geom::Drum2D::Drum2D ( )
inline

Constructor.

Definition at line 1791 of file geomObjects.h.

1792 : GeomObject("drum2d", ""),
1793 d_r(0.),
1794 d_w(0.),
1795 d_a(util::Point(1., 0., 0.)),
1796 d_x(util::Point()),
1797 d_vertices(std::vector<util::Point>(6, util::Point())) {
1798 };
util::Point d_a
Axis: defined as the vector pointing from center to the first vertex v3 v2.
std::vector< util::Point > d_vertices
Vertices.
double d_r
Distance between center and the farthest vertex.
double d_w
Half width of neck.
util::Point d_x
Center.
GeomObject(std::string name="", std::string description="")
Constructor.
A structure to represent 3d vectors.
Definition point.h:30

◆ Drum2D() [2/2]

geom::Drum2D::Drum2D ( double  r,
double  w,
util::Point  x = util::Point(0., 0., 0.),
util::Point  a = util::Point(1., 0., 0.),
std::string  description = "" 
)
inline

Constructor.

Parameters
rDistance between center and farthest vertex of drum2d structure
wHalf of the distance between two vertices in the neck (half width of neck)
xCenter point
aAxis vector that will be rotated and scaled by r to get the farthest four vertices of structure
descriptionDescription of object (e.g., further classification or any tag)

Definition at line 1810 of file geomObjects.h.

1813 : GeomObject("drum2d", description),
1814 d_r(r),
1815 d_w(w),
1816 d_a(a),
1817 d_x(x),
1818 d_vertices(std::vector<util::Point>(6, util::Point())) {
1819 // generate vertices in the plane perpendicular to rotate_axis (z for axis a in xy)
1820 const util::Point rotate_axis(0., 0., 1.);
1821
1822 d_vertices[0] = d_x + d_w * d_a;
1823 d_vertices[3] = d_x - d_w * d_a;
1824
1825 d_vertices[1] = d_x + d_r * util::rotate(d_a, M_PI / 3., rotate_axis);
1826 /* Option 2 used (v1 - k*z_hat), which is not in the drum plane for a in xy and
1827 * breaks coplanarity (e.g. z != 0 on some corners) -> degenerate nodal volumes. */
1828 d_vertices[2] = d_x + d_r * util::rotate(d_a, 2. * M_PI / 3., rotate_axis);
1829
1830 d_vertices[4] = d_x + d_r * util::rotate(-1. * d_a, M_PI / 3., rotate_axis);
1831 d_vertices[5] = d_x + d_r * util::rotate(-1. * d_a, 2. * M_PI / 3., rotate_axis);
1832 };
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_w, d_x, and util::rotate().

Here is the call graph for this function:

Member Function Documentation

◆ boundingRadius()

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

935 {
936
937 return d_r;
938 }

References d_r.

◆ box() [1/2]

std::pair< util::Point, util::Point > geom::Drum2D::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 917 of file geomObjects.cpp.

917 {
918
919 return box(0.);
920 }
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::Drum2D::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 922 of file geomObjects.cpp.

923 {
924
925 auto p1 = d_x - util::Point(d_r + tol, d_r + tol, d_x[2] + tol);
926 auto p2 = d_x + util::Point(d_r + tol, d_r + tol, d_x[2] + tol);
927 return {p1, p2};
928 }

References d_r, and d_x.

◆ center()

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

Computes the center of object.

Returns
Point Coordinates of center

Reimplemented from geom::GeomObject.

Definition at line 913 of file geomObjects.cpp.

913 {
914 return d_x;
915 }

References d_x.

◆ doesIntersect() [1/2]

bool geom::Drum2D::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 1025 of file geomObjects.cpp.

1026 {
1027
1028 // need to check all four corner points
1029 for (auto p: geom::getCornerPoints(2, box))
1030 if (this->isInside(p))
1031 return true;
1032
1033 return false;
1034 }
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::Drum2D::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 992 of file geomObjects.cpp.

992 {
993
994 return isNearBoundary(x, 1.0E-8, false);
995 }
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::Drum2D::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 930 of file geomObjects.cpp.

930 {
931
932 return d_w;
933 }

References d_w.

Referenced by isInside(), and isNearBoundary().

Here is the caller graph for this function:

◆ isInside() [1/2]

bool geom::Drum2D::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 997 of file geomObjects.cpp.

998 {
999
1000 for (auto p: geom::getCornerPoints(2, box))
1001 if (!this->isInside(p))
1002 return false;
1003
1004 return true;
1005 }

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

Here is the call graph for this function:

◆ isInside() [2/2]

bool geom::Drum2D::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 940 of file geomObjects.cpp.

940 {
941
942 if ((x - d_x).length() > d_r)
943 return false;
944
945 if ((x - d_x).length() < inscribedRadius())
946 return true;
947
948 // rotate axis to get orthogonal axis
949 auto ortho_axis = util::rotate(d_a, M_PI * 0.5, util::Point(0., 0., 1.));
950
951 //
952 // + v2
953 // /
954 // / x
955 // /
956 // /
957 // o----+v1
958 //
959 auto ox = x - d_x;
960 double angle_ox_ov1 = std::acos(std::abs(d_a.dot(ox)) / ox.length());
961 double max_length = d_w + angle_ox_ov1 * (d_r - d_w) / (M_PI / 3.);
962
963 return ox.length() <= max_length;
964 }
double inscribedRadius() const override
Computes the radius of biggest circle/sphere completely within the object.
double dot(const Point &b) const
Computes the dot product of this vector with another point.
Definition point.h:138

References d_a, d_r, d_w, d_x, util::Point::dot(), inscribedRadius(), and util::rotate().

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::Drum2D::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 1018 of file geomObjects.cpp.

1020 {
1021
1022 return geom::areBoxesNear(this->box(), box, tol, 2);
1023 }
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::Drum2D::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 970 of file geomObjects.cpp.

971 {
972
973 // get a bigger box containing this object
974 auto bbox = box(tol);
975
976 return geom::isPointInsideBox(x, 2, bbox);
977 }
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::Drum2D::isNearBoundary ( const util::Point x,
const double &  tol,
const bool &  within 
) const
overridevirtual

cons

cons

Reimplemented from geom::GeomObject.

Definition at line 979 of file geomObjects.cpp.

981 {
982
983 if ((x - d_x).length() > d_r + tol)
984 return false;
985
986 if ((x - d_x).length() < this->inscribedRadius() - tol)
987 return false;
988
989 return true;
990 }

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::Drum2D::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 1007 of file geomObjects.cpp.

1008 {
1009
1010 bool intersect = false;
1011 for (auto p: geom::getCornerPoints(2, box))
1012 if (!intersect)
1013 intersect = this->isInside(p);
1014
1015 return !intersect;
1016 }

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

Here is the call graph for this function:

◆ isOutside() [2/2]

bool geom::Drum2D::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 966 of file geomObjects.cpp.

966 {
967 return !isInside(x);
968 }

References isInside().

Here is the call graph for this function:

◆ operator=()

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

Assignment operator.

Parameters
otherObject to copy from
Returns
Reference to this object

Definition at line 1839 of file geomObjects.h.

1839 {
1840 if (this != &other) {
1841 // Copy base class members
1842 d_tags = other.d_tags;
1843
1844 // Copy member variables
1845 d_r = other.d_r;
1846 d_w = other.d_w;
1847 d_a = other.d_a;
1848 d_x = other.d_x;
1849 d_vertices = other.d_vertices;
1850 }
1851 return *this;
1852 }
std::vector< std::string > d_tags
Tags/attributes about the object.
double d_x
the x coordinate
Definition point.h:33

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

◆ print() [1/2]

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

Prints the information about the object.

Reimplemented from geom::GeomObject.

Definition at line 1985 of file geomObjects.h.

1985{ 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::Drum2D::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 1978 of file geomObjects.h.

1978 {
1979 std::cout << printStr(nt, lvl);
1980 };
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::Drum2D::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 1036 of file geomObjects.cpp.

1036 {
1037
1038 auto tabS = util::io::getTabS(nt);
1039
1040 std::ostringstream oss;
1041
1042 oss << tabS << "------- Drum2D --------" << std::endl << std::endl;
1043 oss << tabS << "Name = " << d_name << std::endl;
1044 oss << tabS << "Radius = " << d_r << std::endl;
1045 oss << tabS << "Neck half-width = " << d_w << std::endl;
1046 oss << tabS << "Center = " << d_x.printStr(0, lvl) << std::endl;
1047 oss << tabS << "Axis = " << d_a.printStr(0, lvl) << std::endl;
1048 oss << tabS << "Vertices = " << util::io::printStr(d_vertices, lvl) <<
1049 std::endl;
1050 oss << std::endl;
1051
1052 if (lvl == 0)
1053 oss << std::endl;
1054
1055 return oss.str();
1056 }
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_w, 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::Drum2D::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 1854 of file geomObjects.h.

1855 {
1856 // Scale the dimensions
1857 d_r *= scale;
1858 d_w *= scale;
1859
1860 const util::Point c0 = d_x;
1861 for (auto &v : d_vertices) {
1862 v = mapSimilarity(v, c0, translation, scale, angle, axis, rotationPoint);
1863 }
1864 d_x = mapSimilarity(c0, c0, translation, scale, angle, axis, rotationPoint);
1865 d_a = util::rotate(d_a, angle, axis);
1866 }
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_w, d_x, geom::mapSimilarity(), and util::rotate().

Here is the call graph for this function:

◆ volume()

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

908 {
909
910 return (2. * d_r * d_r - d_r * (d_r - 2. * d_w)) * std::sin(M_PI / 3.);
911 }

References d_r, and d_w.

Field Documentation

◆ d_a

util::Point geom::Drum2D::d_a

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

  • +
                 +         o           +
                v4         x            v1

          +                                +
          v5                               v6

Axis is a unit vector from x to v1

Definition at line 1785 of file geomObjects.h.

Referenced by Drum2D(), isInside(), operator=(), printStr(), and transform().

◆ d_r

double geom::Drum2D::d_r

Distance between center and the farthest vertex.

Definition at line 1769 of file geomObjects.h.

Referenced by boundingRadius(), box(), Drum2D(), isInside(), isNearBoundary(), operator=(), printStr(), transform(), and volume().

◆ d_vertices

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

◆ d_w

double geom::Drum2D::d_w

Half width of neck.

Definition at line 1766 of file geomObjects.h.

Referenced by Drum2D(), inscribedRadius(), isInside(), operator=(), printStr(), transform(), and volume().

◆ d_x

util::Point geom::Drum2D::d_x

Center.

Definition at line 1763 of file geomObjects.h.

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


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