Ocean
Ocean::TriangleT2< T > Class Template Reference

This class implements a 2D triangle with Cartesian coordinates. More...

Inheritance diagram for Ocean::TriangleT2< T >:

Public Member Functions

 TriangleT2 ()=default
 Creates a new 2D triangle object with default parameters. More...
 
 TriangleT2 (const VectorT2< T > &point0, const VectorT2< T > &point1, const VectorT2< T > &point2)
 Creates a new 2D triangle object by three corner positions. More...
 
const VectorT2< T > & point0 () const
 Returns the first triangle corner. More...
 
const VectorT2< T > & point1 () const
 Returns the second triangle corner. More...
 
const VectorT2< T > & point2 () const
 Returns the third triangle corner. More...
 
sqrDistance01 () const
 Returns the square distance between point0 and point1. More...
 
sqrDistance02 () const
 Returns the square distance between point0 and point2. More...
 
sqrDistance12 () const
 Returns the square distance between point1 and point2. More...
 
left () const
 Returns the most left position of this triangle. More...
 
top () const
 Returns the most top position of this triangle. More...
 
right () const
 Returns the most right position of this triangle. More...
 
bottom () const
 Returns the most bottom position of this triangle. More...
 
area () const
 Returns the area of this triangle. More...
 
area2 () const
 Returns the square area of this triangle. More...
 
void cosines (T &cosine0, T &cosine1, T &cosine2) const
 Calculates the three angle cosine values of the three triangle corners. More...
 
void angles (T &angle0, T &angle1, T &angle2) const
 Calculates the three angles of the three triangle corners. More...
 
minAngle () const
 Returns the minimal angle of this triangle. More...
 
bool allCosineBelow (const T cosValue) const
 Returns whether all cosine values of the three triangle corners are below or equal to a given threshold. More...
 
maxSqrLength () const
 Returns the maximal square side length of this triangle. More...
 
maxLength () const
 Returns the maximal side length of this triangle. More...
 
minSqrLength () const
 Returns the minimal square side length of this triangle. More...
 
minLength () const
 Returns the minimal side length of this triangle. More...
 
bool isInside (const VectorT2< T > &point) const
 Returns whether a given point lies inside this triangle. More...
 
bool isCounterClockwise (const bool yAxisDownwards=true) const
 Returns whether this triangles is defined in a counter clockwise manner. More...
 
VectorT2< T > barycentric2cartesian (const VectorT3< T > &barycentric) const
 Returns the 2D Cartesian coordinate of a given barycentric coordinate defined in relation to this triangle. More...
 
VectorT3< T > cartesian2barycentric (const VectorT2< T > &cartesian) const
 Returns the barycentric coordinate of a given 2D Cartesian coordinate defined in relation to this triangle. More...
 
VectorT3< T > barycentricCircumcenter () const
 Returns the circumcenter for this triangle in barycentric coordinates. More...
 
VectorT2< T > cartesianCircumcenter () const
 Returns the circumcenter for this triangle in Cartesian coordinates. More...
 
VectorT3< T > barycentricIncenter () const
 Returns the incenter for this triangle in barycentric coordinates. More...
 
VectorT2< T > cartesianIncenter () const
 Returns the incenter for this triangle in Cartesian coordinates. More...
 
bool intersects (const TriangleT2< T > &triangle) const
 Returns whether this triangle has an intersection with a second triangle. More...
 
TriangleT2< T > padded (const T padWidth) const
 Pad a given 2D triangle along each edge by a fixed value. More...
 
bool isValid () const
 Returns whether this triangle can provide valid barycentric coordinates (for 64 bit floating point values). More...
 
const VectorT2< T > & operator[] (const unsigned int index) const
 Returns individual triangle corners. More...
 
TriangleT2< T > operator+ (const VectorT2< T > &offset) const
 Shifts the triangle by a given 2D vector (by adding the vector to all three corners of the triangle). More...
 
TriangleT2< T > & operator+= (const VectorT2< T > &offset)
 Shifts the triangle by a given 2D vector (by adding the vector to all three corners of the triangle). More...
 
TriangleT2< T > operator- (const VectorT2< T > &offset) const
 Shifts the triangle by a given 2D vector (by subtracting the vector from all three corners of the triangle). More...
 
TriangleT2< T > & operator-= (const VectorT2< T > &offset)
 Shifts the triangle by a given 2D vector (by subtracting the vector from all three corners of the triangle). More...
 

Static Public Member Functions

static bool isInside (const std::vector< TriangleT2< T >> &triangles, const VectorT2< T > &point)
 Returns whether a given point lies inside at least one of the given triangles. More...
 
static T analyzePoints (const VectorT2< T > &point0, const VectorT2< T > &point1, const VectorT2< T > &point2, const bool yAxisDownwards)
 Analyses the layout of three 2D points forming either a triangle or a line. More...
 
- Static Public Member Functions inherited from Ocean::TriangleT< T >
static bool isBarycentricInside (const VectorT3< T > &barycentricPoint)
 Returns whether a given point, specified as barycentric coordinate, lies inside a triangle. More...
 
static bool isValidBarycentric (const VectorT3< T > &barycentric, const T &epsilon=NumericT< T >::eps())
 Returns whether the a barycentric coordinate is valid. More...
 

Private Attributes

VectorT2< T > points_ [3] = {VectorT2<T>(T(0), T(0)), VectorT2<T>(T(0), T(0)), VectorT2<T>(T(0), T(0))}
 The corner positions. More...
 
barycentricFactor_ = T(0)
 Convert factor for barycentric coordinates. More...
 

Detailed Description

template<typename T>
class Ocean::TriangleT2< T >

This class implements a 2D triangle with Cartesian coordinates.

Template Parameters
TData type used to represent coordinates
See also
TriangleF2, TriangleD2, TriangleT3.

Constructor & Destructor Documentation

◆ TriangleT2() [1/2]

template<typename T >
Ocean::TriangleT2< T >::TriangleT2 ( )
default

Creates a new 2D triangle object with default parameters.

◆ TriangleT2() [2/2]

template<typename T >
Ocean::TriangleT2< T >::TriangleT2 ( const VectorT2< T > &  point0,
const VectorT2< T > &  point1,
const VectorT2< T > &  point2 
)
inline

Creates a new 2D triangle object by three corner positions.

Parameters
point0First corner position
point1Second corner position
point2Third corner position

Member Function Documentation

◆ allCosineBelow()

template<typename T >
bool Ocean::TriangleT2< T >::allCosineBelow ( const T  cosValue) const

Returns whether all cosine values of the three triangle corners are below or equal to a given threshold.

Thus, to test whether the minimal corner angle is equal to PI/8, then allCosineBelow(cos(PI/8)) has to be checked.

Parameters
cosValueCosine threshold value
Returns
True, if so

◆ analyzePoints()

template<typename T >
T Ocean::TriangleT2< T >::analyzePoints ( const VectorT2< T > &  point0,
const VectorT2< T > &  point1,
const VectorT2< T > &  point2,
const bool  yAxisDownwards 
)
static

Analyses the layout of three 2D points forming either a triangle or a line.

The result of the function depends on the coordinate system in which the points are defined:

First coordinate system,     Second coordinate system

 ------> x-axis              ^
|                            | y-axis
|                            |
| y-axis                     |
V                             ------> x-axis

Parameters
point0The first point to be analyzed
point1The first point to be analyzed
point2The first point to be analyzed
yAxisDownwardsTrue, if the y-axis points downwards and x-axis points to the right; False, if the y-axis points upwards and the x-axis points to the right
Returns
A negative value if the three points define a counter clockwise triangle, a positive value for a clockwise triangle, zero is the tree points are located on a line, with range (-infinity, infinity)

◆ angles()

template<typename T >
void Ocean::TriangleT2< T >::angles ( T &  angle0,
T &  angle1,
T &  angle2 
) const
inline

Calculates the three angles of the three triangle corners.

Beware: Make sure that this triangle is valid before!

Parameters
angle0Resulting angle corresponding to point0 in radian
angle1Resulting angle corresponding to point1 in radian
angle2Resulting angle corresponding to point2 in radian

◆ area()

template<typename T >
T Ocean::TriangleT2< T >::area
inline

Returns the area of this triangle.

Returns
Triangle area
See also
area2().

◆ area2()

template<typename T >
T Ocean::TriangleT2< T >::area2
inline

Returns the square area of this triangle.

Returns
Triangle area
See also
area().

◆ barycentric2cartesian()

template<typename T >
VectorT2< T > Ocean::TriangleT2< T >::barycentric2cartesian ( const VectorT3< T > &  barycentric) const
inline

Returns the 2D Cartesian coordinate of a given barycentric coordinate defined in relation to this triangle.

Parameters
barycentricThe Barycentric coordinate to convert to a Cartesian coordinate
Returns
Cartesian coordinate

◆ barycentricCircumcenter()

template<typename T >
VectorT3< T > Ocean::TriangleT2< T >::barycentricCircumcenter

Returns the circumcenter for this triangle in barycentric coordinates.

Returns
Barycentric coordinates of the circumcenter

◆ barycentricIncenter()

template<typename T >
VectorT3< T > Ocean::TriangleT2< T >::barycentricIncenter

Returns the incenter for this triangle in barycentric coordinates.

Returns
Barycentric coordinates of the incenter

◆ bottom()

template<typename T >
T Ocean::TriangleT2< T >::bottom
inline

Returns the most bottom position of this triangle.

Returns
Bottom position

◆ cartesian2barycentric()

template<typename T >
VectorT3< T > Ocean::TriangleT2< T >::cartesian2barycentric ( const VectorT2< T > &  cartesian) const
inline

Returns the barycentric coordinate of a given 2D Cartesian coordinate defined in relation to this triangle.

Parameters
cartesianThe Cartesian coordinate to convert to a barycentric coordinate
Returns
Barycentric coordinate

◆ cartesianCircumcenter()

template<typename T >
VectorT2< T > Ocean::TriangleT2< T >::cartesianCircumcenter
inline

Returns the circumcenter for this triangle in Cartesian coordinates.

Returns
Cartesian coordinates of the circumcenter

◆ cartesianIncenter()

template<typename T >
VectorT2< T > Ocean::TriangleT2< T >::cartesianIncenter
inline

Returns the incenter for this triangle in Cartesian coordinates.

Returns
Cartesian coordinates of the circumcenter

◆ cosines()

template<typename T >
void Ocean::TriangleT2< T >::cosines ( T &  cosine0,
T &  cosine1,
T &  cosine2 
) const

Calculates the three angle cosine values of the three triangle corners.

Beware: Make sure that this triangle is valid before!

Parameters
cosine0Resulting angle corresponding to point0
cosine1Resulting angle corresponding to point1
cosine2Resulting angle corresponding to point2

◆ intersects()

template<typename T >
bool Ocean::TriangleT2< T >::intersects ( const TriangleT2< T > &  triangle) const

Returns whether this triangle has an intersection with a second triangle.

Parameters
triangleThe second triangle to test
Returns
True, if so

◆ isCounterClockwise()

template<typename T >
bool Ocean::TriangleT2< T >::isCounterClockwise ( const bool  yAxisDownwards = true) const
inline

Returns whether this triangles is defined in a counter clockwise manner.

The result of the function depends on the coordinate system in which the points are defined:

First coordinate system,     Second coordinate system

 ------> x-axis              ^
|                            | y-axis
|                            |
| y-axis                     |
V                             ------> x-axis

Parameters
yAxisDownwardsTrue, if the y-axis points downwards and x-axis points to the right; False, if the y-axis points upwards and the x-axis points to the right
Returns
True, if so

◆ isInside() [1/2]

template<typename T >
bool Ocean::TriangleT2< T >::isInside ( const std::vector< TriangleT2< T >> &  triangles,
const VectorT2< T > &  point 
)
inlinestatic

Returns whether a given point lies inside at least one of the given triangles.

Parameters
trianglesThe triangles that are tested
pointThe point to be checked
Returns
True, if so

◆ isInside() [2/2]

template<typename T >
bool Ocean::TriangleT2< T >::isInside ( const VectorT2< T > &  point) const
inline

Returns whether a given point lies inside this triangle.

Parameters
pointThe point to be checked
Returns
True, if so

◆ isValid()

template<typename T >
bool Ocean::TriangleT2< T >::isValid
inline

Returns whether this triangle can provide valid barycentric coordinates (for 64 bit floating point values).

For 32 bit floating point values we simply check whether all three corners of the triangle are different.

Returns
True, if so

◆ left()

template<typename T >
T Ocean::TriangleT2< T >::left
inline

Returns the most left position of this triangle.

Returns
Left position

◆ maxLength()

template<typename T >
T Ocean::TriangleT2< T >::maxLength
inline

Returns the maximal side length of this triangle.

Returns
Maximal side length

◆ maxSqrLength()

template<typename T >
T Ocean::TriangleT2< T >::maxSqrLength
inline

Returns the maximal square side length of this triangle.

Returns
Maximal square side length

◆ minAngle()

template<typename T >
T Ocean::TriangleT2< T >::minAngle
inline

Returns the minimal angle of this triangle.

Beware: Make sure that this triangle is valid before!

Returns
Minimal angle in radian

◆ minLength()

template<typename T >
T Ocean::TriangleT2< T >::minLength
inline

Returns the minimal side length of this triangle.

Returns
Minimal side length

◆ minSqrLength()

template<typename T >
T Ocean::TriangleT2< T >::minSqrLength
inline

Returns the minimal square side length of this triangle.

Returns
Minimal square side length

◆ operator+()

template<typename T >
TriangleT2< T > Ocean::TriangleT2< T >::operator+ ( const VectorT2< T > &  offset) const
inline

Shifts the triangle by a given 2D vector (by adding the vector to all three corners of the triangle).

Parameters
offsetThe offset vector to shift the triangle
Returns
The new shifted triangle

◆ operator+=()

template<typename T >
TriangleT2< T > & Ocean::TriangleT2< T >::operator+= ( const VectorT2< T > &  offset)
inline

Shifts the triangle by a given 2D vector (by adding the vector to all three corners of the triangle).

Parameters
offsetThe offset vector to shift the triangle
Returns
The reference to this triangle

◆ operator-()

template<typename T >
TriangleT2< T > Ocean::TriangleT2< T >::operator- ( const VectorT2< T > &  offset) const
inline

Shifts the triangle by a given 2D vector (by subtracting the vector from all three corners of the triangle).

Parameters
offsetThe offset vector to shift the triangle
Returns
The new shifted triangle

◆ operator-=()

template<typename T >
TriangleT2< T > & Ocean::TriangleT2< T >::operator-= ( const VectorT2< T > &  offset)
inline

Shifts the triangle by a given 2D vector (by subtracting the vector from all three corners of the triangle).

Parameters
offsetThe offset vector to shift the triangle
Returns
The reference to this triangle

◆ operator[]()

template<typename T >
const VectorT2< T > & Ocean::TriangleT2< T >::operator[] ( const unsigned int  index) const
inline

Returns individual triangle corners.

Parameters
indexIndex of the corner that is requested, with range [0, 2]
Returns
Resulting triangle corner

◆ padded()

template<typename T >
TriangleT2< T > Ocean::TriangleT2< T >::padded ( const T  padWidth) const

Pad a given 2D triangle along each edge by a fixed value.

For a positive pad width, each side of the resulting triangle is shifted away from the triangle circumcenter along the perpendicular.

Parameters
padWidthAbsolute amount to shift the triangle edges out from the triangle circumcenter, with range (-infinity, infinity); note that, in the case where the padding is negative with an absolute value smaller than the shortest distance from the circumcenter to an edge, then the triangle will flip its orientation
Returns
Padded 2D triangle

◆ point0()

template<typename T >
const VectorT2< T > & Ocean::TriangleT2< T >::point0
inline

Returns the first triangle corner.

Returns
First triangle corner

◆ point1()

template<typename T >
const VectorT2< T > & Ocean::TriangleT2< T >::point1
inline

Returns the second triangle corner.

Returns
Second triangle corner

◆ point2()

template<typename T >
const VectorT2< T > & Ocean::TriangleT2< T >::point2
inline

Returns the third triangle corner.

Returns
Third triangle corner

◆ right()

template<typename T >
T Ocean::TriangleT2< T >::right
inline

Returns the most right position of this triangle.

Returns
Right position

◆ sqrDistance01()

template<typename T >
T Ocean::TriangleT2< T >::sqrDistance01
inline

Returns the square distance between point0 and point1.

Returns
Square distance

◆ sqrDistance02()

template<typename T >
T Ocean::TriangleT2< T >::sqrDistance02
inline

Returns the square distance between point0 and point2.

Returns
Square distance

◆ sqrDistance12()

template<typename T >
T Ocean::TriangleT2< T >::sqrDistance12
inline

Returns the square distance between point1 and point2.

Returns
Square distance

◆ top()

template<typename T >
T Ocean::TriangleT2< T >::top
inline

Returns the most top position of this triangle.

Returns
Top position

Field Documentation

◆ barycentricFactor_

template<typename T >
T Ocean::TriangleT2< T >::barycentricFactor_ = T(0)
private

Convert factor for barycentric coordinates.

◆ points_

template<typename T >
VectorT2<T> Ocean::TriangleT2< T >::points_[3] = {VectorT2<T>(T(0), T(0)), VectorT2<T>(T(0), T(0)), VectorT2<T>(T(0), T(0))}
private

The corner positions.


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