https://mooseframework.inl.gov
Loading...
Searching...
No Matches
Public Member Functions | Private Attributes | List of all members
Triangle Class Reference

Triangle geometry helper. More...

#include <Triangle.h>

Inheritance diagram for Triangle:
[legend]

Public Member Functions

 Triangle ()=default
 
 Triangle (const libMesh::Point &p0, const libMesh::Point &p1, const libMesh::Point &p2)
 
 ~Triangle () override=default
 
libMesh::Point normal () const
 Normal vector of the triangle.
 
bool intersect (const LineSegment &l, libMesh::Point &intersect_p) const
 Check if a line segment intersects this triangle.
 
bool intersect (const LineSegment &line_segment) const override
 Check if a line segment intersects this triangle, without returning the intersection point.
 
Ball computeBoundingBall () const override
 Compute a bounding ball for this triangle.
 

Private Attributes

libMesh::Point _p0
 
libMesh::Point _p1
 
libMesh::Point _p2
 

Detailed Description

Triangle geometry helper.

Definition at line 21 of file Triangle.h.

Constructor & Destructor Documentation

◆ Triangle() [1/2]

Triangle::Triangle ( )
default

◆ Triangle() [2/2]

Triangle::Triangle ( const libMesh::Point &  p0,
const libMesh::Point &  p1,
const libMesh::Point &  p2 
)

◆ ~Triangle()

Triangle::~Triangle ( )
overridedefault

Member Function Documentation

◆ computeBoundingBall()

Ball Triangle::computeBoundingBall ( ) const
overridevirtual

Compute a bounding ball for this triangle.

Implements GeometryBase.

Definition at line 88 of file Triangle.C.

89{
90 const Point centroid = (_p0 + _p1 + _p2) / 3.0;
91
92 Real max_sq_dist = 0.0;
93 for (const auto * p : {&_p0, &_p1, &_p2})
94 {
95 const Real dist_sq = (*p - centroid).norm_sq();
96 if (dist_sq > max_sq_dist)
97 max_sq_dist = dist_sq;
98 }
99
100 const Real radius = std::sqrt(max_sq_dist);
101 return Ball(centroid, radius);
102}
Ball primitive: a circle in 2D or a sphere in 3D.
Definition Ball.h:35
libMesh::Point _p2
Definition Triangle.h:50
libMesh::Point _p0
Definition Triangle.h:50
libMesh::Point _p1
Definition Triangle.h:50
auto norm_sq(const T &a)
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
const Real radius

Referenced by SurfaceTri3::computeBoundingBall().

◆ intersect() [1/2]

bool Triangle::intersect ( const LineSegment &  l,
libMesh::Point &  intersect_p 
) const

Check if a line segment intersects this triangle.

Referenced by SurfaceTri3::intersect(), and intersect().

◆ intersect() [2/2]

bool Triangle::intersect ( const LineSegment &  line_segment) const
overridevirtual

Check if a line segment intersects this triangle, without returning the intersection point.

Implements GeometryBase.

Definition at line 81 of file Triangle.C.

82{
84 return intersect(line_segment, p);
85}
bool intersect(const LineSegment &l, libMesh::Point &intersect_p) const
Check if a line segment intersects this triangle.

◆ normal()

Point Triangle::normal ( ) const

Normal vector of the triangle.

Definition at line 21 of file Triangle.C.

22{
23 const auto v1 = _p1 - _p0;
24 const auto v2 = _p2 - _p0;
25
26 const auto n = v1.cross(v2);
27 const Real norm = n.norm();
28 if (norm == 0.0)
29 mooseError("Triangle: cannot compute the normal of a degenerate triangle.");
30
31 return n / norm;
32}
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Definition MooseError.h:311
TypeVector< typename CompareTypes< Real, T2 >::supertype > cross(const TypeVector< T2 > &v) const
auto norm(const T &a)

Member Data Documentation

◆ _p0

libMesh::Point Triangle::_p0
private

Definition at line 50 of file Triangle.h.

Referenced by computeBoundingBall(), and normal().

◆ _p1

libMesh::Point Triangle::_p1
private

Definition at line 50 of file Triangle.h.

Referenced by computeBoundingBall(), and normal().

◆ _p2

libMesh::Point Triangle::_p2
private

Definition at line 50 of file Triangle.h.

Referenced by computeBoundingBall(), and normal().


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