8#ifndef META_OCEAN_MATH_TRIANGLE_2_H
9#define META_OCEAN_MATH_TRIANGLE_2_H
179 void cosines(T& cosine0, T& cosine1, T& cosine2)
const;
188 inline void angles(T& angle0, T& angle1, T& angle2)
const;
481 return std::max((T(4) * a2 * c2 -
NumericT<T>::sqr(a2 + c2 - b2)) * T(0.0625), T(0));
537 const T coord0 = a2 * (-a2 + b2 + c2);
538 const T coord1 = b2 * (a2 - b2 + c2);
539 const T coord2 = c2 * (a2 + b2 - c2);
541 const T total = coord0 + coord1 + coord2;
544 const T factor = T(1) / total;
546 return VectorT3<T>(coord0 * factor, coord1 * factor, coord2 * factor);
558 const T total = a + b + c;
561 const T factor = T(1) / total;
563 return VectorT3<T>(a * factor, b * factor, c * factor);
632 line01 /= line01.
xy().length();
633 line12 /= line12.
xy().length();
634 line20 /= line20.
xy().length();
636 if (line01 * hPoint2 > T(0.0))
644 line01.
z() -= padWidth;
645 line12.
z() -= padWidth;
646 line20.
z() -= padWidth;
668 T cosine0, cosine1, cosine2;
669 cosines(cosine0, cosine1, cosine2);
679 T cosine0, cosine1, cosine2;
680 cosines(cosine0, cosine1, cosine2);
696 return max(sqrLength01, max(sqrLength02, sqrLength12));
712 return min(sqrLength01, min(sqrLength02, sqrLength12));
732 if (triangle.isInside(point))
755 (
points_[0].y() * barycentric[0] +
points_[1].y() * barycentric[1] +
points_[2].y() * barycentric[2]));
770 if (std::is_same<float, Scalar>::value)
780 return VectorT3<T>(barycentric0, barycentric1, T(1) - barycentric0 - barycentric1);
800 if (std::is_same<T, double>::value)
813 ocean_assert(index <= 2u);
857 return vector01.
cross(vector02);
861 return -vector01.
cross(vector02);
This class implements an finite line in 2D space.
Definition FiniteLine2.h:82
bool intersects(const FiniteLineT2< T > &second) const
Returns whether two finite lines have a unique intersection point.
Definition FiniteLine2.h:578
static constexpr T weakEps()
Returns a weak epsilon.
static constexpr bool isInsideRange(const T lower, const T value, const T upper, const T epsilon=NumericT< T >::eps())
Returns whether a value lies between a given range up to a provided epsilon border.
Definition Numeric.h:2881
static T abs(const T value)
Returns the absolute value of a given value.
Definition Numeric.h:1220
static constexpr T pi()
Returns PI which is equivalent to 180 degree.
Definition Numeric.h:926
static bool isWeakEqual(const T first, const T second)
Returns whether two values a equal up to a weak epsilon.
Definition Numeric.h:2581
static T sqrt(const T value)
Returns the square root of a given value.
Definition Numeric.h:1537
static constexpr T sqr(const T value)
Returns the square of a given value.
Definition Numeric.h:1499
static constexpr bool isEqualEps(const T value)
Returns whether a value is smaller than or equal to a small epsilon.
Definition Numeric.h:2096
static T acos(const T value)
Returns the arccosine of a given value.
Definition Numeric.h:2916
static constexpr bool isNotEqualEps(const T value)
Returns whether a value is not smaller than or equal to a small epsilon.
Definition Numeric.h:2246
This class implements a 2D triangle with Cartesian coordinates.
Definition Triangle2.h:81
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.
Definition Triangle2.h:728
VectorT3< T > cartesian2barycentric(const VectorT2< T > &cartesian) const
Returns the barycentric coordinate of a given 2D Cartesian coordinate defined in relation to this tri...
Definition Triangle2.h:759
const VectorT2< T > & operator[](const unsigned int index) const
Returns individual triangle corners.
Definition Triangle2.h:811
T maxLength() const
Returns the maximal side length of this triangle.
Definition Triangle2.h:700
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).
Definition Triangle2.h:824
bool isInside(const VectorT2< T > &point) const
Returns whether a given point lies inside this triangle.
Definition Triangle2.h:722
T sqrDistance01() const
Returns the square distance between point0 and point1.
Definition Triangle2.h:422
T area() const
Returns the area of this triangle.
Definition Triangle2.h:468
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).
Definition Triangle2.h:818
T left() const
Returns the most left position of this triangle.
Definition Triangle2.h:440
TriangleT2(const VectorT2< T > &point0, const VectorT2< T > &point1, const VectorT2< T > &point2)
Creates a new 2D triangle object by three corner positions.
Definition Triangle2.h:387
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 tri...
Definition Triangle2.h:840
T area2() const
Returns the square area of this triangle.
Definition Triangle2.h:474
T minLength() const
Returns the minimal side length of this triangle.
Definition Triangle2.h:716
const VectorT2< Scalar > & point2() const
bool isCounterClockwise(const bool yAxisDownwards=true) const
Returns whether this triangles is defined in a counter clockwise manner.
Definition Triangle2.h:742
Scalar barycentricFactor_
Definition Triangle2.h:383
T sqrDistance02() const
Returns the square distance between point0 and point2.
Definition Triangle2.h:428
void angles(T &angle0, T &angle1, T &angle2) const
Calculates the three angles of the three triangle corners.
Definition Triangle2.h:666
VectorT2< T > barycentric2cartesian(const VectorT3< T > &barycentric) const
Returns the 2D Cartesian coordinate of a given barycentric coordinate defined in relation to this tri...
Definition Triangle2.h:750
T top() const
Returns the most top position of this triangle.
Definition Triangle2.h:447
VectorT2< T > cartesianIncenter() const
Returns the incenter for this triangle in Cartesian coordinates.
Definition Triangle2.h:791
bool allCosineBelow(const T cosValue) const
Returns whether all cosine values of the three triangle corners are below or equal to a given thresho...
Definition Triangle2.h:508
T sqrDistance12() const
Returns the square distance between point1 and point2.
Definition Triangle2.h:434
const VectorT2< Scalar > & point0() const
bool intersects(const TriangleT2< T > &triangle) const
Returns whether this triangle has an intersection with a second triangle.
Definition Triangle2.h:567
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.
Definition Triangle2.h:850
void cosines(T &cosine0, T &cosine1, T &cosine2) const
Calculates the three angle cosine values of the three triangle corners.
Definition Triangle2.h:485
T minAngle() const
Returns the minimal angle of this triangle.
Definition Triangle2.h:677
T maxSqrLength() const
Returns the maximal square side length of this triangle.
Definition Triangle2.h:690
VectorT3< T > barycentricIncenter() const
Returns the incenter for this triangle in barycentric coordinates.
Definition Triangle2.h:550
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 tri...
Definition Triangle2.h:834
T right() const
Returns the most right position of this triangle.
Definition Triangle2.h:454
VectorT3< T > barycentricCircumcenter() const
Returns the circumcenter for this triangle in barycentric coordinates.
Definition Triangle2.h:529
VectorT2< T > cartesianCircumcenter() const
Returns the circumcenter for this triangle in Cartesian coordinates.
Definition Triangle2.h:784
const VectorT2< Scalar > & point1() const
TriangleT2()=default
Creates a new 2D triangle object with default parameters.
TriangleT2< T > padded(const T padWidth) const
Pad a given 2D triangle along each edge by a fixed value.
Definition Triangle2.h:602
bool isValid() const
Returns whether this triangle can provide valid barycentric coordinates (for 64 bit floating point va...
Definition Triangle2.h:798
T bottom() const
Returns the most bottom position of this triangle.
Definition Triangle2.h:461
VectorT2< Scalar > points_[3]
Definition Triangle2.h:380
T minSqrLength() const
Returns the minimal square side length of this triangle.
Definition Triangle2.h:706
This class implements a base class for all triangle classes.
Definition Triangle.h:49
static bool isBarycentricInside(const VectorT3< T > &barycentricPoint)
Returns whether a given point, specified as barycentric coordinate, lies inside a triangle.
Definition Triangle.h:69
static bool isValidBarycentric(const VectorT3< T > &barycentric, const T &epsilon=NumericT< T >::eps())
Returns whether the a barycentric coordinate is valid.
Definition Triangle.h:77
This class implements a vector with two elements.
Definition Vector2.h:96
const T & x() const noexcept
Returns the x value.
Definition Vector2.h:703
const T & y() const noexcept
Returns the y value.
Definition Vector2.h:715
T cross(const VectorT2< T > &vector) const
Returns the cross product of two 2D vectors.
Definition Vector2.h:549
This class implements a vector with three elements.
Definition Vector3.h:97
VectorT3< T > cross(const VectorT3< T > &vector) const
Returns the cross product of two vectors.
Definition Vector3.h:601
VectorT2< T > xy() const noexcept
Returns the x and y component of the vector as new 2D vector.
Definition Vector3.h:840
const T & z() const noexcept
Returns the z value.
Definition Vector3.h:828
unsigned int sqrDistance(const char first, const char second)
Returns the square distance between two values.
Definition base/Utilities.h:1159
std::vector< TriangleD2 > TrianglesD2
Definition of a vector holding 2D triangles with double precision float data type.
Definition Triangle2.h:71
TriangleT2< double > TriangleD2
Instantiation of the TriangleT2 template class using a double precision float data type.
Definition Triangle2.h:35
std::vector< TriangleT2< T > > TrianglesT2
Definition of a typename alias for vectors with TriangleT2 objects.
Definition Triangle2.h:50
std::vector< TriangleF2 > TrianglesF2
Definition of a vector holding 2D triangles with single precision float data type.
Definition Triangle2.h:64
TriangleT2< float > TriangleF2
Instantiation of the TriangleT2 template class using a single precision float data type.
Definition Triangle2.h:42
std::vector< Triangle2 > Triangles2
Definition of a vector holding 2D triangles.
Definition Triangle2.h:57
TriangleT2< Scalar > Triangle2
Definition of the Triangle2 object, depending on the OCEAN_MATH_USE_SINGLE_PRECISION either with sing...
Definition Triangle2.h:28
The namespace covering the entire Ocean framework.
Definition Accessor.h:15