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

Defines Drum2D. More...

#include <geomObjects.h>

Inheritance diagram for util::geometry::Drum2D:
Collaboration diagram for util::geometry::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.
 
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_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 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 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 1230 of file geomObjects.h.

Constructor & Destructor Documentation

◆ Drum2D() [1/2]

util::geometry::Drum2D::Drum2D ( )
inline

Constructor.

Definition at line 1236 of file geomObjects.h.

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

◆ Drum2D() [2/2]

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

1257 : GeomObject("drum2d", description),
1258 d_r(r),
1259 d_w(w),
1260 d_a(a),
1261 d_x(x),
1262 d_vertices(std::vector<util::Point>(6, util::Point())) {
1263
1264 // generate vertices
1265 auto rotate_axis = util::Point(0., 0., 1.); // z-axis
1266
1267 // half-width of big (top and bottom) edge
1268 double w_big_edge = d_r * std::cos(M_PI / 3.);
1269
1270 d_vertices[0] = d_x + d_w * d_a;
1271 d_vertices[3] = d_x - d_w * d_a;
1272
1273 d_vertices[1] =
1274 d_x + d_r * util::rotate(d_a, M_PI / 3., rotate_axis);
1275 // to get third vertex, we could either rotate axis further or use second vertex to get
1276 // to the third vertex
1277 // Option 1
1278 // d_vertices[2] = d_x + d_r * util::rotate(d_a, 2.*M_PI/3., rotate_axis);
1279 // Option 2
1280 d_vertices[2] = d_vertices[1] - 2 * w_big_edge * rotate_axis;
1281
1282 d_vertices[4] = d_x + d_r * util::rotate(-1. * d_a, M_PI / 3.,
1283 rotate_axis);
1284 // Option 2
1285 d_vertices[5] = d_vertices[4] + 2. * w_big_edge * d_a;
1286 };
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 util::geometry::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 util::geometry::GeomObject.

Definition at line 786 of file geomObjects.cpp.

786 {
787
788 return d_r;
789 }

◆ box() [1/2]

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

Definition at line 768 of file geomObjects.cpp.

768 {
769
770 return box(0.);
771 }
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::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 util::geometry::GeomObject.

Definition at line 773 of file geomObjects.cpp.

774 {
775
776 auto p1 = d_x - util::Point(d_r + tol, d_r + tol, d_x[2] + tol);
777 auto p2 = d_x + util::Point(d_r + tol, d_r + tol, d_x[2] + tol);
778 return {p1, p2};
779 }

◆ center()

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

Computes the center of object.

Returns
Point Coordinates of center

Reimplemented from util::geometry::GeomObject.

Definition at line 764 of file geomObjects.cpp.

764 {
765 return d_x;
766 }

◆ doesIntersect() [1/2]

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

Definition at line 876 of file geomObjects.cpp.

877 {
878
879 // need to check all four corner points
880 for (auto p: util::getCornerPoints(2, box))
881 if (this->isInside(p))
882 return true;
883
884 return false;
885 }
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::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 util::geometry::GeomObject.

Definition at line 843 of file geomObjects.cpp.

843 {
844
845 return isNearBoundary(x, 1.0E-8, false);
846 }
bool isNearBoundary(const util::Point &x, const double &tol, const bool &within) const override
cons

◆ inscribedRadius()

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

781 {
782
783 return d_w;
784 }

◆ isInside() [1/2]

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

Definition at line 848 of file geomObjects.cpp.

849 {
850
851 for (auto p: util::getCornerPoints(2, box))
852 if (!this->isInside(p))
853 return false;
854
855 return true;
856 }

References util::getCornerPoints().

Here is the call graph for this function:

◆ isInside() [2/2]

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

Definition at line 791 of file geomObjects.cpp.

791 {
792
793 if ((x - d_x).length() > d_r)
794 return false;
795
796 if ((x - d_x).length() < inscribedRadius())
797 return true;
798
799 // rotate axis to get orthogonal axis
800 auto ortho_axis = util::rotate(d_a, M_PI * 0.5, util::Point(0., 0., 1.));
801
802 //
803 // + v2
804 // /
805 // / x
806 // /
807 // /
808 // o----+v1
809 //
810 auto ox = x - d_x;
811 double angle_ox_ov1 = std::acos(std::abs(d_a.dot(ox)) / ox.length());
812 double max_length = d_w + angle_ox_ov1 * (d_r - d_w) / (M_PI / 3.);
813
814 return ox.length() <= max_length;
815 }
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:132

References util::rotate().

Here is the call graph for this function:

◆ isNear() [1/2]

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

Definition at line 869 of file geomObjects.cpp.

871 {
872
873 return util::areBoxesNear(this->box(), box, tol, 2);
874 }
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::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 util::geometry::GeomObject.

Definition at line 821 of file geomObjects.cpp.

822 {
823
824 // get a bigger box containing this object
825 auto bbox = box(tol);
826
827 return util::isPointInsideBox(x, 2, bbox);
828 }
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::Drum2D::isNearBoundary ( const util::Point x,
const double &  tol,
const bool &  within 
) const
overridevirtual

cons

cons

Reimplemented from util::geometry::GeomObject.

Definition at line 830 of file geomObjects.cpp.

832 {
833
834 if ((x - d_x).length() > d_r + tol)
835 return false;
836
837 if ((x - d_x).length() < this->inscribedRadius() - tol)
838 return false;
839
840 return true;
841 }

◆ isOutside() [1/2]

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

Definition at line 858 of file geomObjects.cpp.

859 {
860
861 bool intersect = false;
862 for (auto p: util::getCornerPoints(2, box))
863 if (!intersect)
864 intersect = this->isInside(p);
865
866 return !intersect;
867 }

References util::getCornerPoints().

Here is the call graph for this function:

◆ isOutside() [2/2]

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

Definition at line 817 of file geomObjects.cpp.

817 {
818 return !isInside(x);
819 }

◆ print() [1/2]

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

Prints the information about the object.

Reimplemented from util::geometry::GeomObject.

Definition at line 1405 of file geomObjects.h.

1405{ 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::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 util::geometry::GeomObject.

Definition at line 1398 of file geomObjects.h.

1398 {
1399 std::cout << printStr(nt, lvl);
1400 };
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::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 util::geometry::GeomObject.

Definition at line 887 of file geomObjects.cpp.

887 {
888
889 auto tabS = util::io::getTabS(nt);
890
891 std::ostringstream oss;
892
893 oss << tabS << "------- Drum2D --------" << std::endl << std::endl;
894 oss << tabS << "Name = " << d_name << std::endl;
895 oss << tabS << "Radius = " << d_r << std::endl;
896 oss << tabS << "Neck half-width = " << d_w << std::endl;
897 oss << tabS << "Center = " << d_x.printStr(0, lvl) << std::endl;
898 oss << tabS << "Axis = " << d_a.printStr(0, lvl) << std::endl;
899 oss << tabS << "Vertices = " << util::io::printStr(d_vertices, lvl) <<
900 std::endl;
901 oss << std::endl;
902
903 if (lvl == 0)
904 oss << std::endl;
905
906 return oss.str();
907 }
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::Drum2D::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 759 of file geomObjects.cpp.

759 {
760
761 return (2. * d_r * d_r - d_r * (d_r - 2. * d_w)) * std::sin(M_PI / 3.);
762 }

Field Documentation

◆ d_a

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

Referenced by Drum2D().

◆ d_r

double util::geometry::Drum2D::d_r

Distance between center and the farthest vertex.

Definition at line 1417 of file geomObjects.h.

Referenced by Drum2D().

◆ d_vertices

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

Vertices.

Definition at line 1408 of file geomObjects.h.

Referenced by Drum2D().

◆ d_w

double util::geometry::Drum2D::d_w

Half width of neck.

Definition at line 1414 of file geomObjects.h.

Referenced by Drum2D().

◆ d_x

util::Point util::geometry::Drum2D::d_x

Center.

Definition at line 1411 of file geomObjects.h.

Referenced by Drum2D().


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