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

Defines Triangle. More...

#include <geomObjects.h>

Inheritance diagram for geom::Triangle:
Collaboration diagram for geom::Triangle:

Public Member Functions

 Triangle ()
 Constructor.
 
 Triangle (double r, util::Point x=util::Point(0., 0., 0.), util::Point a=util::Point(1., 0., 0.), std::string description="uniform")
 Constructor.
 
 Triangle (util::Point v0, util::Point v1, util::Point v2, std::string description="vertices")
 Constructor from three vertices (arbitrary triangle, e.g. a V-notch). Params in decks: x1,y1,z1, x2,y2,z2, x3,y3,z3.
 
 Triangle (const Triangle &other)
 Copy constructor.
 
Triangleoperator= (const Triangle &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

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 triangle.
 
util::Point d_a
 Axis: defined as the vector pointing from center to the first vertex 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 Triangle.

Definition at line 759 of file geomObjects.h.

Constructor & Destructor Documentation

◆ Triangle() [1/4]

geom::Triangle::Triangle ( )
inline

Constructor.

Definition at line 790 of file geomObjects.h.

791 : GeomObject("triangle", ""),
792 d_r(0.),
793 d_a(util::Point(1., 0., 0.)),
794 d_x(util::Point()),
795 d_vertices(std::vector<util::Point>(3, util::Point())) {
796 };
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 v2 +.
std::vector< util::Point > d_vertices
Vertices.
double d_r
Distance between center and the farthest vertex of triangle.
A structure to represent 3d vectors.
Definition point.h:30

◆ Triangle() [2/4]

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

Constructor.

Parameters
rRadius (distance of vertex from center)
xCenter point
aAxis vector that will be rotated and scaled by r to find coordiantes of triangle vertices
descriptionDescription of object (e.g., further classification or any tag)

Definition at line 806 of file geomObjects.h.

809 : GeomObject("triangle", description),
810 d_r(r),
811 d_a(a),
812 d_x(x),
813 d_vertices(std::vector<util::Point>(3, util::Point())) {
814 // generate vertices
815 auto rotate_axis = util::Point(0., 0., 1.); // z-axis
816 for (int i = 0; i < 3; i++) {
818 d_a, i * 2. * M_PI / 3., rotate_axis);
819 }
820 };
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:

◆ Triangle() [3/4]

geom::Triangle::Triangle ( util::Point  v0,
util::Point  v1,
util::Point  v2,
std::string  description = "vertices" 
)
inline

Constructor from three vertices (arbitrary triangle, e.g. a V-notch). Params in decks: x1,y1,z1, x2,y2,z2, x3,y3,z3.

Definition at line 826 of file geomObjects.h.

828 : GeomObject("triangle", description),
829 d_r(0.),
830 d_a(util::Point(1., 0., 0.)),
831 d_x(util::Point()),
832 d_vertices({v0, v1, v2}) {
833 d_x = (v0 + v1 + v2) / 3.0;
834 d_r = (v0 - d_x).length();
835 {
836 const double r1 = (v1 - d_x).length();
837 const double r2 = (v2 - d_x).length();
838 if (r1 > d_r)
839 d_r = r1;
840 if (r2 > d_r)
841 d_r = r2;
842 }
843 d_a = v0 - d_x;
844 if (d_a.length() > 0.)
845 d_a = d_a / d_a.length();
846 };
double length() const
Computes the Euclidean length of the vector.
Definition point.h:124

◆ Triangle() [4/4]

geom::Triangle::Triangle ( const Triangle other)
inline

Copy constructor.

Parameters
otherObject to copy from

Definition at line 852 of file geomObjects.h.

853 : GeomObject(other.d_name, other.d_description),
854 d_r(other.d_r),
855 d_a(other.d_a),
856 d_x(other.d_x),
857 d_vertices(other.d_vertices) {
858 d_tags = other.d_tags;
859 }
std::vector< std::string > d_tags
Tags/attributes about the object.

References geom::GeomObject::d_tags.

Member Function Documentation

◆ boundingRadius()

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

289 {
290
291 return d_r;
292 }

References d_r.

◆ box() [1/2]

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

264 {
265
266 return box(0.);
267 }
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::Triangle::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 269 of file geomObjects.cpp.

270 {
271
272 util::Point p1 = d_vertices[0], p2 = d_vertices[0];
273 for (const auto &v : d_vertices) {
274 p1.d_x = std::min(p1.d_x, v.d_x);
275 p1.d_y = std::min(p1.d_y, v.d_y);
276 p1.d_z = std::min(p1.d_z, v.d_z);
277 p2.d_x = std::max(p2.d_x, v.d_x);
278 p2.d_y = std::max(p2.d_y, v.d_y);
279 p2.d_z = std::max(p2.d_z, v.d_z);
280 }
281 return {p1 - tol, p2 + tol};
282 }
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_vertices, util::Point::d_x, util::Point::d_y, and util::Point::d_z.

◆ center()

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

Computes the center of object.

Returns
Point Coordinates of center

Reimplemented from geom::GeomObject.

Definition at line 260 of file geomObjects.cpp.

260 {
261 return d_x;
262 }

References d_x.

◆ doesIntersect() [1/2]

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

389 {
390
391 // need to check all four corner points
392 for (auto p: geom::getCornerPoints(2, box))
393 if (this->isInside(p))
394 return true;
395
396 return false;
397 }
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::Triangle::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 355 of file geomObjects.cpp.

355 {
356
357 return isNearBoundary(x, 1.0E-8, false);
358 }
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::Triangle::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 284 of file geomObjects.cpp.

284 {
285
286 return d_r * std::sin(M_PI / 3);
287 }

References d_r.

Referenced by isInside().

Here is the caller graph for this function:

◆ isInside() [1/2]

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

361 {
362
363 for (auto p: geom::getCornerPoints(2, box))
364 if (!this->isInside(p))
365 return false;
366
367 return true;
368 }

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

Here is the call graph for this function:

◆ isInside() [2/2]

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

294 {
295
296 if ((x - d_x).length() > d_r)
297 return false;
298
299 if ((x - d_x).length() < this->inscribedRadius())
300 return true;
301
302 double a = this->volume();
303 double a1 =
304 std::abs(geom::triangleArea(x, d_vertices[1], d_vertices[2]));
305 double a2 =
306 std::abs(geom::triangleArea(d_vertices[0], x, d_vertices[2]));
307 double a3 =
308 std::abs(geom::triangleArea(d_vertices[0], d_vertices[1], x));
309
310 return (a1 + a2 + a3 <= a * (1.0 + 1.0e-10));
311 }
double inscribedRadius() const override
Computes the radius of biggest circle/sphere completely within the object.
double volume() const override
Computes the volume (area in 2d, length in 1d) of object.
double triangleArea(const util::Point &x1, const util::Point &x2, const util::Point &x3)
Compute area of triangle.

References d_r, d_vertices, d_x, inscribedRadius(), geom::triangleArea(), and volume().

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::Triangle::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 381 of file geomObjects.cpp.

383 {
384
385 return geom::areBoxesNear(this->box(), box, tol, 2);
386 }
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::Triangle::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 317 of file geomObjects.cpp.

318 {
319
320 // get a bigger box containing this object
321 auto bbox = box(tol);
322
323 return geom::isPointInsideBox(x, 2, bbox);
324 }
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().

Referenced by isNearBoundary().

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

◆ isNearBoundary()

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

cons

cons

Reimplemented from geom::GeomObject.

Definition at line 326 of file geomObjects.cpp.

328 {
329
330 // check if particle is inside the object
331 if (!isNear(x, within ? 0. : tol))
332 return false;
333
334 double a = this->volume();
335 double l = 0.5 * std::sqrt(a);
336
337 double a1 =
338 std::abs(geom::triangleArea(x, d_vertices[1], d_vertices[2]));
339 if (a1 < tol * l)
340 return true;
341
342 double a2 =
343 std::abs(geom::triangleArea(d_vertices[0], x, d_vertices[2]));
344 if (a2 < tol * l)
345 return true;
346
347 double a3 =
348 std::abs(geom::triangleArea(d_vertices[0], d_vertices[1], x));
349 if (a3 < tol * l)
350 return true;
351
352 return false;
353 }
bool isNear(const util::Point &x, const double &tol) const override
Checks if point is within given distance of this object.

References d_vertices, isNear(), geom::triangleArea(), and volume().

Referenced by doesIntersect().

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

◆ isOutside() [1/2]

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

371 {
372
373 bool intersect = false;
374 for (auto p: geom::getCornerPoints(2, box))
375 if (!intersect)
376 intersect = this->isInside(p);
377
378 return !intersect;
379 }

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

Here is the call graph for this function:

◆ isOutside() [2/2]

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

313 {
314 return !isInside(x);
315 }

References isInside().

Here is the call graph for this function:

◆ operator=()

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

Assignment operator.

Parameters
otherObject to copy from
Returns
Reference to this object

Definition at line 866 of file geomObjects.h.

866 {
867 if (this != &other) {
868 // Copy base class members
869 d_tags = other.d_tags;
870
871 // Copy member variables
872 d_r = other.d_r;
873 d_a = other.d_a;
874 d_x = other.d_x;
875 d_vertices = other.d_vertices;
876 }
877 return *this;
878 }

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

◆ print() [1/2]

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

Prints the information about the object.

Reimplemented from geom::GeomObject.

Definition at line 1011 of file geomObjects.h.

1011{ 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::Triangle::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 1004 of file geomObjects.h.

1004 {
1005 std::cout << printStr(nt, lvl);
1006 };
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::Triangle::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 399 of file geomObjects.cpp.

399 {
400
401 auto tabS = util::io::getTabS(nt);
402
403 std::ostringstream oss;
404
405 oss << tabS << "------- Triangle --------" << std::endl << std::endl;
406 oss << tabS << "Name = " << d_name << std::endl;
407 oss << tabS << "Center = " << d_x.printStr(0, lvl) << std::endl;
408 oss << tabS << "Radius = " << d_r << std::endl;
409 oss << tabS << "Vertices = " << util::io::printStr(d_vertices)
410 << std::endl;
411 oss << std::endl;
412
413 if (lvl == 0)
414 oss << std::endl;
415
416 return oss.str();
417 }
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 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::Triangle::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 880 of file geomObjects.h.

881 {
882 // Scale the radius
883 d_r *= scale;
884
885 const util::Point c0 = d_x;
886 for (auto &v : d_vertices) {
887 v = mapSimilarity(v, c0, translation, scale, angle, axis, rotationPoint);
888 }
889 d_x = mapSimilarity(c0, c0, translation, scale, angle, axis, rotationPoint);
890 d_a = util::rotate(d_a, angle, axis);
891 }
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::Triangle::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 255 of file geomObjects.cpp.

255 {
256 // 2D area of the stored triangle (works for equilateral and vertex-defined).
257 return std::abs(geom::triangleArea(d_vertices[0], d_vertices[1], d_vertices[2]));
258 }

References d_vertices, and geom::triangleArea().

Referenced by isInside(), and isNearBoundary().

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

Field Documentation

◆ d_a

util::Point geom::Triangle::d_a

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

                           o           +
                           x            v1

                   +
                   v3

Axis is a vector from x to v1

Definition at line 784 of file geomObjects.h.

Referenced by operator=(), transform(), and Triangle().

◆ d_r

double geom::Triangle::d_r

Distance between center and the farthest vertex of triangle.

Definition at line 768 of file geomObjects.h.

Referenced by boundingRadius(), inscribedRadius(), isInside(), operator=(), printStr(), transform(), and Triangle().

◆ d_vertices

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

Vertices.

Definition at line 762 of file geomObjects.h.

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

◆ d_x

util::Point geom::Triangle::d_x

Center.

Definition at line 765 of file geomObjects.h.

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


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