Gazebo Math

API Reference

8.0.0
Triangle3< T > Class Template Reference

A 3-dimensional triangle and related functions. More...

#include <gz/math/Triangle3.hh>

Public Member Functions

 Triangle3 ()=default
 Default constructor.
 
 Triangle3 (const Vector3< T > &_pt1, const Vector3< T > &_pt2, const Vector3< T > &_pt3)
 Constructor.
 
double Area () const
 Get the area of this triangle.
 
bool Contains (const Line3< T > &_line) const
 Check if this triangle completely contains the given line segment.
 
bool Contains (const Vector3< T > &_pt) const
 Get whether this triangle contains the given point.
 
bool Intersects (const Line3< T > &_line, Vector3< T > &_ipt1) const
 Get whether the given line intersects an edge of this triangle.
 
Vector3d Normal () const
 Get the triangle's normal vector.
 
Vector3< T > operator[] (const size_t _index) const
 Get one of points that define the triangle.
 
Perimeter () const
 Get the length of the triangle's perimeter.
 
void Set (const unsigned int _index, const Vector3< T > &_pt)
 Set one vertex of the triangle.
 
void Set (const Vector3< T > &_pt1, const Vector3< T > &_pt2, const Vector3< T > &_pt3)
 Set all vertices of the triangle.
 
Line3< T > Side (const unsigned int _index) const
 Get a line segment for one side of the triangle.
 
bool Valid () const
 Get whether this triangle is valid, based on triangle inequality: the sum of the lengths of any two sides must be greater than the length of the remaining side.
 

Detailed Description

template<typename T>
class gz::math::Triangle3< T >

A 3-dimensional triangle and related functions.

Constructor & Destructor Documentation

◆ Triangle3() [1/2]

template<typename T >
Triangle3 ( )
default

Default constructor.

◆ Triangle3() [2/2]

template<typename T >
Triangle3 ( const Vector3< T > &  _pt1,
const Vector3< T > &  _pt2,
const Vector3< T > &  _pt3 
)
inline

Constructor.

Keep in mind that the triangle normal is determined by the order of these vertices. Search the internet for "triangle winding" for more information.

Parameters
[in]_pt1First point that defines the triangle.
[in]_pt2Second point that defines the triangle.
[in]_pt3Third point that defines the triangle.

References Triangle3< T >::Set().

Member Function Documentation

◆ Area()

template<typename T >
double Area ( ) const
inline

Get the area of this triangle.

Returns
Triangle's area.

References Triangle3< T >::Perimeter(), and Triangle3< T >::Side().

◆ Contains() [1/2]

template<typename T >
bool Contains ( const Line3< T > &  _line) const
inline

Check if this triangle completely contains the given line segment.

Parameters
[in]_lineLine to check.
Returns
True if the line's start and end points are both inside this triangle.

References Triangle3< T >::Contains().

Referenced by Triangle3< T >::Contains(), and Triangle3< T >::Intersects().

◆ Contains() [2/2]

template<typename T >
bool Contains ( const Vector3< T > &  _pt) const
inline

Get whether this triangle contains the given point.

Parameters
[in]_ptPoint to check.
Returns
True if the point is inside or on the triangle.

References Triangle3< T >::Normal(), and Triangle3< T >::Side().

◆ Intersects()

template<typename T >
bool Intersects ( const Line3< T > &  _line,
Vector3< T > &  _ipt1 
) const
inline

Get whether the given line intersects an edge of this triangle.

The returned intersection point is one of:

  • If the line is coplanar with the triangle:
    • The point on the closest edge of the triangle that the line intersects. OR
    • The first point on the line, if the line is completely contained
  • If the line is not coplanar, the point on the triangle that the line intersects.
Parameters
[in]_lineLine to check.
[out]_ipt1Return value of the first intersection point, only valid if the return value of the function is true.
Returns
True if the given line intersects this triangle.

References Triangle3< T >::Contains(), gz::math::equal(), and Triangle3< T >::Normal().

◆ Normal()

template<typename T >
Vector3d Normal ( ) const
inline

Get the triangle's normal vector.

Returns
The normal vector for the triangle.

References Vector3< T >::Normal().

Referenced by Triangle3< T >::Contains(), and Triangle3< T >::Intersects().

◆ operator[]()

template<typename T >
Vector3< T > operator[] ( const size_t  _index) const
inline

Get one of points that define the triangle.

Parameters
[in]_index0, 1, or 2. _index is clamped to the range [0,2].
Returns
The triangle point at _index.

References gz::math::clamp(), gz::math::GZ_TWO_SIZE_T, and gz::math::GZ_ZERO_SIZE_T.

◆ Perimeter()

template<typename T >
T Perimeter ( ) const
inline

Get the length of the triangle's perimeter.

Returns
Sum of the triangle's line segments.

References Triangle3< T >::Side().

Referenced by Triangle3< T >::Area().

◆ Set() [1/2]

template<typename T >
void Set ( const unsigned int  _index,
const Vector3< T > &  _pt 
)
inline

Set one vertex of the triangle.

Keep in mind that the triangle normal is determined by the order of these vertices. Search the internet for "triangle winding" for more information.

Parameters
[in]_indexIndex of the point to set. _index is clamped to the range [0,2].
[in]_ptValue of the point to set.

References gz::math::clamp().

Referenced by Triangle3< T >::Triangle3().

◆ Set() [2/2]

template<typename T >
void Set ( const Vector3< T > &  _pt1,
const Vector3< T > &  _pt2,
const Vector3< T > &  _pt3 
)
inline

Set all vertices of the triangle.

Keep in mind that the triangle normal is determined by the order of these vertices. Search the internet for "triangle winding" for more information.

Parameters
[in]_pt1First point that defines the triangle.
[in]_pt2Second point that defines the triangle.
[in]_pt3Third point that defines the triangle.

◆ Side()

template<typename T >
Line3< T > Side ( const unsigned int  _index) const
inline

Get a line segment for one side of the triangle.

Parameters
[in]_indexIndex of the side to retrieve, where 0 == Line3(pt1, pt2), 1 == Line3(pt2, pt3), 2 == Line3(pt3, pt1). _index is clamped to the range [0,2].
Returns
Line segment of the requested side.

Referenced by Triangle3< T >::Area(), Triangle3< T >::Contains(), Triangle3< T >::Perimeter(), and Triangle3< T >::Valid().

◆ Valid()

template<typename T >
bool Valid ( ) const
inline

Get whether this triangle is valid, based on triangle inequality: the sum of the lengths of any two sides must be greater than the length of the remaining side.

Returns
True if the triangle inequality holds

References Triangle3< T >::Side().


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