42#ifndef UFO_GEOMETRY_TRIANGLE_HPP
43#define UFO_GEOMETRY_TRIANGLE_HPP
46#include <ufo/geometry/aabb.hpp>
47#include <ufo/numeric/vec.hpp>
69template <std::
size_t Dim = 3, std::
floating_po
int T =
float>
95 Vec<Dim, T> point_3) noexcept
96 :
points{point_1, point_2, point_3}
105 template <std::convertible_to<T> U>
115 [[nodiscard]]
static constexpr std::size_t
dimension() noexcept {
return Dim; }
122 [[nodiscard]]
constexpr auto&
operator[](
this auto& self, std::size_t pos)
noexcept
124 return self.points[pos];
142 [[nodiscard]]
constexpr T
area() const noexcept
149 return T(0.5) * std::sqrt(std::max(T(0), d1 * d2 - d12 * d12));
182 T eps = std::numeric_limits<T>::epsilon()) const noexcept
184 return area() <= eps;
191 [[nodiscard]]
constexpr T
volume() const noexcept {
return T(0); }
197 [[nodiscard]]
constexpr T
diameter() const noexcept
214template <std::
size_t Dim, std::
floating_po
int T>
220template <std::
size_t Dim, std::
floating_po
int T>
223 return out <<
"Point 1: [" << triangle[0] <<
"], Point 2: [" << triangle[1]
224 <<
"], Point 3: [" << triangle[2] <<
"]";
227template <std::
floating_po
int T>
228using Triangle1 = Triangle<1, T>;
229template <std::
floating_po
int T>
230using Triangle2 = Triangle<2, T>;
231template <std::
floating_po
int T>
232using Triangle3 = Triangle<3, T>;
233template <std::
floating_po
int T>
234using Triangle4 = Triangle<4, T>;
236using Triangle1f = Triangle<1, float>;
237using Triangle2f = Triangle<2, float>;
238using Triangle3f = Triangle<3, float>;
239using Triangle4f = Triangle<4, float>;
241using Triangle1d = Triangle<1, double>;
242using Triangle2d = Triangle<2, double>;
243using Triangle3d = Triangle<3, double>;
244using Triangle4d = Triangle<4, double>;
248template <std::
size_t Dim, std::
floating_po
int T>
249 requires std::formattable<T, char>
250struct std::formatter<
ufo::Triangle<Dim, T>> {
251 constexpr auto parse(std::format_parse_context& ctx) {
return ctx.begin(); }
255 return std::format_to(ctx.out(),
"Points: [{}], [{}], [{}]", triangle[0], triangle[1],
constexpr T dot(Quat< T > const &a, Quat< T > const &b) noexcept
Computes the four-component dot product a.w*b.w + a.x*b.x + a.y*b.y + a.z*b.z.
All vision-related classes and functions.
constexpr T normSquared(Quat< T > const &q) noexcept
Returns the squared norm (dot product with itself).
constexpr Vec< Geometry::dimension(), typename Geometry::value_type > max(Geometry const &g)
Returns the maximum coordinate of the minimum spanning axis-aligned bounding box of a geometry.
constexpr Quat< T > normalize(Quat< T > const &q) noexcept
Returns a unit quaternion in the same direction as q.
constexpr Quat< T > cross(Quat< T > const &q1, Quat< T > const &q2) noexcept
Computes the Hamilton cross product of two quaternions.
constexpr Vec< Geometry::dimension(), typename Geometry::value_type > min(Geometry const &g)
Returns the minimum coordinate of the minimum spanning axis-aligned bounding box of a geometry.
Axis-Aligned Bounding Box (AABB) in Dim-dimensional space.
Triangle in Dim-dimensional space.
std::array< Vec< Dim, T >, 3 > points
The vertices of the triangle.
bool operator==(Triangle const &) const =default
Equality operator.
constexpr T diameter() const noexcept
Returns the diameter of the triangle.
constexpr Triangle(Triangle< Dim, U > const &other) noexcept
Converting constructor from a triangle with a different scalar type.
constexpr Triangle() noexcept=default
Default constructor.
constexpr T volume() const noexcept
Returns the volume of the triangle.
constexpr bool isDegenerate(T eps=std::numeric_limits< T >::epsilon()) const noexcept
Returns true if the triangle is degenerate.
constexpr T area() const noexcept
Returns the area of the triangle.
constexpr AABB< Dim, T > aabb() const noexcept
Returns the AABB of the triangle.
constexpr Vec< Dim, T > center() const noexcept
Returns the centroid (arithmetic mean) of the triangle.
static constexpr std::size_t dimension() noexcept
Returns the dimensionality of the triangle.
constexpr Vec< 3, T > normal() const noexcept
Returns the surface unit normal of the triangle.
constexpr auto & operator[](this auto &self, std::size_t pos) noexcept
Returns the vertex at position pos.
A fixed-size arithmetic vector of up to 4 dimensions.