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

Defines Triangle. More...

#include <geomObjects.h>

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

Definition at line 454 of file geomObjects.h.

Constructor & Destructor Documentation

◆ Triangle() [1/2]

util::geometry::Triangle::Triangle ( )
inline

Constructor.

Definition at line 460 of file geomObjects.h.

461 : GeomObject("triangle", ""),
462 d_r(0.),
463 d_a(util::Point(1., 0., 0.)),
464 d_x(util::Point()),
465 d_vertices(std::vector<util::Point>(3, util::Point())) {};
GeomObject(std::string name="", std::string description="")
Constructor.
Definition geomObjects.h:39
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/2]

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

478 : GeomObject("triangle", description),
479 d_r(r),
480 d_a(a),
481 d_x(x),
482 d_vertices(std::vector<util::Point>(3, util::Point())) {
483
484 // generate vertices
485 auto rotate_axis = util::Point(0., 0., 1.); // z-axis
486 for (int i = 0; i < 3; i++) {
488 d_a, i * 2. * M_PI / 3., rotate_axis);
489 }
490 };
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::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 util::geometry::GeomObject.

Definition at line 210 of file geomObjects.cpp.

210 {
211
212 return d_r;
213 }

◆ box() [1/2]

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

Definition at line 190 of file geomObjects.cpp.

190 {
191
192 return box(0.);
193 }
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::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 util::geometry::GeomObject.

Definition at line 195 of file geomObjects.cpp.

196 {
197
198 // find lower and upper coordinates
199 auto p1 = util::Point(d_x.d_x - d_r, d_x.d_y - d_r, d_x.d_z);
200 auto p2 = util::Point(d_x.d_x + d_r, d_x.d_y + d_r, d_x.d_z);
201
202 return {p1 - tol, p2 + tol};
203 }
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

◆ center()

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

Computes the center of object.

Returns
Point Coordinates of center

Reimplemented from util::geometry::GeomObject.

Definition at line 186 of file geomObjects.cpp.

186 {
187 return d_x;
188 }

◆ doesIntersect() [1/2]

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

Definition at line 309 of file geomObjects.cpp.

310 {
311
312 // need to check all four corner points
313 for (auto p: util::getCornerPoints(2, box))
314 if (this->isInside(p))
315 return true;
316
317 return false;
318 }
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::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 util::geometry::GeomObject.

Definition at line 276 of file geomObjects.cpp.

276 {
277
278 return isNearBoundary(x, 1.0E-8, false);
279 }
bool isNearBoundary(const util::Point &x, const double &tol, const bool &within) const override
cons

◆ inscribedRadius()

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

205 {
206
207 return d_r * std::sin(M_PI / 3);
208 }

◆ isInside() [1/2]

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

Definition at line 281 of file geomObjects.cpp.

282 {
283
284 for (auto p: util::getCornerPoints(2, box))
285 if (!this->isInside(p))
286 return false;
287
288 return true;
289 }

References util::getCornerPoints().

Here is the call graph for this function:

◆ isInside() [2/2]

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

Definition at line 215 of file geomObjects.cpp.

215 {
216
217 if ((x - d_x).length() > d_r)
218 return false;
219
220 if ((x - d_x).length() < this->inscribedRadius())
221 return true;
222
223 double a = this->volume();
224 double a1 =
225 std::abs(util::triangleArea(x, d_vertices[1], d_vertices[2]));
226 double a2 =
227 std::abs(util::triangleArea(d_vertices[0], x, d_vertices[2]));
228 double a3 =
229 std::abs(util::triangleArea(d_vertices[0], d_vertices[1], x));
230
231 return (a1 + a2 + a3 < a);
232 }
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.
Definition geom.cpp:642

References util::triangleArea().

Here is the call graph for this function:

◆ isNear() [1/2]

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

Definition at line 302 of file geomObjects.cpp.

304 {
305
306 return util::areBoxesNear(this->box(), box, tol, 2);
307 }
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::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 util::geometry::GeomObject.

Definition at line 238 of file geomObjects.cpp.

239 {
240
241 // get a bigger box containing this object
242 auto bbox = box(tol);
243
244 return util::isPointInsideBox(x, 2, bbox);
245 }
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::Triangle::isNearBoundary ( const util::Point x,
const double &  tol,
const bool &  within 
) const
overridevirtual

cons

cons

Reimplemented from util::geometry::GeomObject.

Definition at line 247 of file geomObjects.cpp.

249 {
250
251 // check if particle is inside the object
252 if (!isNear(x, within ? 0. : tol))
253 return false;
254
255 double a = this->volume();
256 double l = 0.5 * std::sqrt(a);
257
258 double a1 =
259 std::abs(util::triangleArea(x, d_vertices[1], d_vertices[2]));
260 if (a1 < tol * l)
261 return true;
262
263 double a2 =
264 std::abs(util::triangleArea(d_vertices[0], x, d_vertices[2]));
265 if (a2 < tol * l)
266 return true;
267
268 double a3 =
269 std::abs(util::triangleArea(d_vertices[0], d_vertices[1], x));
270 if (a3 < tol * l)
271 return true;
272
273 return false;
274 }
bool isNear(const util::Point &x, const double &tol) const override
Checks if point is within given distance of this object.

References util::triangleArea().

Here is the call graph for this function:

◆ isOutside() [1/2]

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

Definition at line 291 of file geomObjects.cpp.

292 {
293
294 bool intersect = false;
295 for (auto p: util::getCornerPoints(2, box))
296 if (!intersect)
297 intersect = this->isInside(p);
298
299 return !intersect;
300 }

References util::getCornerPoints().

Here is the call graph for this function:

◆ isOutside() [2/2]

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

Definition at line 234 of file geomObjects.cpp.

234 {
235 return !isInside(x);
236 }

◆ print() [1/2]

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

Prints the information about the object.

Reimplemented from util::geometry::GeomObject.

Definition at line 610 of file geomObjects.h.

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

Definition at line 603 of file geomObjects.h.

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

Definition at line 320 of file geomObjects.cpp.

320 {
321
322 auto tabS = util::io::getTabS(nt);
323
324 std::ostringstream oss;
325
326 oss << tabS << "------- Triangle --------" << std::endl << std::endl;
327 oss << tabS << "Name = " << d_name << std::endl;
328 oss << tabS << "Center = " << d_x.printStr(0, lvl) << std::endl;
329 oss << tabS << "Radius = " << d_r << std::endl;
330 oss << tabS << "Vertices = " << util::io::printStr(d_vertices)
331 << std::endl;
332 oss << std::endl;
333
334 if (lvl == 0)
335 oss << std::endl;
336
337 return oss.str();
338 }
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::Triangle::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 182 of file geomObjects.cpp.

182 {
183 return d_r * d_r * (1. + std::sin(M_PI / 3));
184 }

Field Documentation

◆ d_a

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

Referenced by Triangle().

◆ d_r

double util::geometry::Triangle::d_r

Distance between center and the farthest vertex of triangle.

Definition at line 619 of file geomObjects.h.

Referenced by Triangle().

◆ d_vertices

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

Vertices.

Definition at line 613 of file geomObjects.h.

Referenced by Triangle().

◆ d_x

util::Point util::geometry::Triangle::d_x

Center.

Definition at line 616 of file geomObjects.h.

Referenced by Triangle().


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