template <typename Scalar>
muu::triangle struct

A triangle.

Template parameters
Scalar The triangle's scalar component type. Must be a floating-point type.

Public types

using const_iterator = const vector_type*
A const LegacyRandomAccessIterator for the points in the triangle.
using constants = muu::constants<triangle>
Compile-time triangle constants.
using iterator = vector_type*
A LegacyRandomAccessIterator for the points in the triangle.
using scalar_type = Scalar
The triangle's scalar type.
using vector_type = vector<scalar_type, 3>
The three-dimensional muu::vector with the same scalar_type as the triangle.

Constructors, destructors, conversion operators

triangle() defaulted noexcept
Default constructor. Values are not initialized.
triangle(const triangle&) defaulted constexpr noexcept
Copy constructor.
triangle(const vector_type& p0, const vector_type& p1, const vector_type& p2) constexpr noexcept
Constructs a triangle from three points.
triangle(const vector_type(&points)[3]) explicit constexpr noexcept
Constructs a triangle from three points.
triangle(scalar_type p0_x, scalar_type p0_y, scalar_type p0_z, scalar_type p1_x, scalar_type p1_y, scalar_type p1_z, scalar_type p2_x, scalar_type p2_y, scalar_type p2_z) constexpr noexcept
Constructs a triangle from three points (in scalar form).
template <typename S>
triangle(const triangle<S>& tri) explicit constexpr noexcept
Converting constructor.
template <typename T>
triangle(const T& obj) constexpr noexcept
Constructs a triangle from an implicitly bit-castable type.

Public functions

auto operator=(const triangle&) -> triangle& defaulted constexpr noexcept
Copy-assigment operator.

Public variables

vector_type points
the points in the triangle.

Barycentric coordinates

static auto barycentric(const vector_type& p0, const vector_type& p1, const vector_type& p2, const vector_type& point) -> vector_type constexpr noexcept
Returns the barycentric coordinates of a point within a triangle.
static auto barycentric_generator(const vector_type& p0, const vector_type& p1, const vector_type& p2) -> auto constexpr noexcept
Returns a generator for calculating multiple barycentric coordinates from the same triangle.
auto barycentric(const vector_type& point) const -> vector_type constexpr noexcept
Returns the barycentric coordinates of a point within the triangle.
auto barycentric_generator() const -> auto constexpr noexcept
Returns a generator for calculating multiple barycentric coordinates from the triangle.

Collision detection

static auto contains(const vector_type& p0, const vector_type& p1, const vector_type& p2, const vector_type& point, scalar_type epsilon = default_epsilon<scalar_type>) -> bool constexpr noexcept
Returns true if a triangle contains a point.
static auto contains(const triangle& tri, const vector_type& point, scalar_type epsilon = default_epsilon<scalar_type>) -> bool constexpr noexcept
Returns true if a triangle contains a point.
static auto contains(const vector_type& p0, const vector_type& p1, const vector_type& p2, const vector_type& start, const vector_type& end, scalar_type epsilon = default_epsilon<scalar_type>) -> bool constexpr noexcept
Returns true if a triangle contains a line segment.
static auto contains(const triangle& tri, const line_segment<scalar_type>& seg, scalar_type epsilon = default_epsilon<scalar_type>) -> bool constexpr noexcept
Returns true if a triangle contains a line segment.
static auto coplanar(const vector_type& p0, const vector_type& p1, const vector_type& p2, const vector_type& point, scalar_type epsilon = default_epsilon<scalar_type>) -> bool constexpr noexcept
Returns true if a triangle and a point are coplanar.
static auto coplanar(const triangle& tri, const vector_type& point, scalar_type epsilon = default_epsilon<scalar_type>) -> bool constexpr noexcept
Returns true if a triangle and a point are coplanar.
static auto intersects(const triangle& tri1, const triangle& tri2, std::optional<line_segment<scalar_type>>& seg) -> bool constexpr noexcept
Returns true if two triangles intersect, plus the line segment of the intersection (if one exists).
static auto intersects(const triangle& tri1, const triangle& tri2) -> bool constexpr noexcept
Returns true if two triangles intersect.
static auto intersects(const vector_type& p0, const vector_type& p1, const vector_type& p2, const bounding_sphere<scalar_type>& bs) -> bool constexpr noexcept
Returns true if a triangle intersects a bounding sphere.
static auto intersects(const triangle& tri, const bounding_sphere<scalar_type>& bs) -> bool constexpr noexcept
Returns true if a triangle intersects a bounding sphere.
static auto intersects(const vector_type& p0, const vector_type& p1, const vector_type& p2, const bounding_box<scalar_type>& bb) -> bool constexpr noexcept
Returns true if a triangle intersects a bounding box.
static auto intersects(const triangle& tri, const bounding_box<scalar_type>& bb) -> bool constexpr noexcept
Returns true if a triangle intersects a bounding box.
static auto intersects(const vector_type& p0, const vector_type& p1, const vector_type& p2, const oriented_bounding_box<scalar_type>& bb) -> bool constexpr noexcept
Returns true if a triangle intersects an oriented bounding box.
static auto intersects(const triangle& tri, const oriented_bounding_box<scalar_type>& bb) -> bool constexpr noexcept
Returns true if a triangle intersects an oriented bounding box.
auto collision_tester() const -> muu::collision_tester<triangle> constexpr noexcept
Creates an #muu::collision_tester for this triangle.
auto contains(const vector_type& point, scalar_type epsilon = default_epsilon<scalar_type>) const -> bool constexpr noexcept
Returns true if the triangle contains a point.
auto contains(const vector_type* begin, const vector_type* end, scalar_type epsilon = default_epsilon<scalar_type>) -> bool constexpr noexcept
Returns true if the triangles contains all the points in an arbitrary collection.
auto contains(const line_segment<scalar_type>& seg, scalar_type epsilon = default_epsilon<scalar_type>) const -> bool constexpr noexcept
Returns true if the triangle contains a line segment.
auto coplanar(const vector_type& point, scalar_type epsilon = default_epsilon<scalar_type>) const -> bool constexpr noexcept
Returns true if the triangle and a point are coplanar.
auto intersects(const triangle& tri, std::optional<line_segment<scalar_type>>& seg) const -> bool constexpr noexcept
Returns true if a triangle intersects with another triangle, plus the line segment of the intersection (if one exists).
auto intersects(const triangle& tri) const -> bool constexpr noexcept
Returns true if a triangle intersects with another triangle.
auto intersects(const bounding_sphere<scalar_type>& bs) const -> bool constexpr noexcept
Returns true if the triangle intersects a bounding sphere.
auto intersects(const bounding_box<scalar_type>& bb) const -> bool constexpr noexcept
Returns true if the triangle intersects a bounding box.
auto intersects(const oriented_bounding_box<scalar_type>& bb) const -> bool constexpr noexcept
Returns true if the triangle intersects an oriented bounding box.

Equality (approximate)

template <typename T>
static auto approx_equal(const triangle& tri1, const triangle<T>& tri2, epsilon_type<scalar_type, T> epsilon = default_epsilon<scalar_type, T>) -> bool constexpr noexcept
Returns true if two triangles are approximately equal.
static auto approx_zero(const triangle& tri, scalar_type epsilon = default_epsilon<scalar_type>) -> bool constexpr noexcept
Returns true if all the scalar components in a triangle are approximately equal to zero.
template <typename T>
auto approx_equal(const triangle<T>& tri, epsilon_type<scalar_type, T> epsilon = default_epsilon<scalar_type, T>) const -> bool constexpr noexcept
Returns true if the triangle is approximately equal to another.
auto approx_zero(scalar_type epsilon = default_epsilon<scalar_type>) const -> bool constexpr noexcept
Returns true if all the scalar components in the triangle are approximately equal to zero.

Equality (exact)

static auto degenerate(const vector_type& p0, const vector_type& p1, const vector_type& p2) -> bool constexpr noexcept
Returns true if a triangle is degenerate (i.e. two or more of its points are coincident).
static auto infinity_or_nan(const triangle& tri) -> bool constexpr noexcept
Returns true if any of the points of a triangle are infinity or NaN.
static auto zero(const triangle& tri) -> bool constexpr noexcept
Returns true if all the points of a triangle are exactly zero.
auto degenerate() const -> bool constexpr noexcept
Returns true if the triangle is degenerate (i.e. two or more of its points are coincident).
auto infinity_or_nan() const -> bool constexpr noexcept
Returns true if any of the points in the triangle are infinity or NaN.
auto zero() const -> bool constexpr noexcept
Returns true if all the points of the triangle are exactly zero.
template <typename T>
auto operator!=(const triangle& lhs, const triangle<T>& rhs) -> bool constexpr noexcept
Returns true if two triangles are not exactly equal.
template <typename T>
auto operator==(const triangle& lhs, const triangle<T>& rhs) -> bool constexpr noexcept
Returns true if two triangles are exactly equal.

Geometric properties

static auto area(const vector_type& p0, const vector_type& p1, const vector_type& p2) -> scalar_type constexpr noexcept
Returns the area of a triangle.
static auto centroid(const vector_type& p0, const vector_type& p1, const vector_type& p2) -> vector_type constexpr noexcept
Returns a triangle's centroid point.
static auto normal(const vector_type& p0, const vector_type& p1, const vector_type& p2) -> vector_type constexpr noexcept
Returns the normal of a triangle's plane.
static auto perimeter(const vector_type& p0, const vector_type& p1, const vector_type& p2) -> scalar_type constexpr noexcept
Returns the length of a triangle's perimeter.
static auto plane(const vector_type& p0, const vector_type& p1, const vector_type& p2) -> muu::plane<scalar_type> constexpr noexcept
Returns the plane on which a triangle lies.
auto area() const -> scalar_type constexpr noexcept
Returns the area of the triangle.
auto centroid() const -> vector_type constexpr noexcept
Returns the triangle's centroid point.
auto normal() const -> vector_type constexpr noexcept
Returns the normal of the triangle's plane.
operator muu::plane<scalar_type>() const explicit constexpr noexcept
Returns the plane on which the triangle lies.
auto perimeter() const -> scalar_type constexpr noexcept
Returns the length of the triangle's perimeter.
auto plane() const -> muu::plane<scalar_type> constexpr noexcept
Returns the plane on which the triangle lies.

Iterators

auto begin() -> iterator constexpr noexcept
Returns an iterator to the first point in the triangle.
auto begin() const -> const_iterator constexpr noexcept
Returns a const iterator to the first point in the triangle.
auto cbegin() const -> const_iterator constexpr noexcept
Returns a const iterator to the first point in the triangle.
auto cend() const -> const_iterator constexpr noexcept
Returns a const iterator to the one-past-the-last point in the triangle.
auto end() -> iterator constexpr noexcept
Returns an iterator to the one-past-the-last point in the triangle.
auto end() const -> const_iterator constexpr noexcept
Returns a const iterator to the one-past-the-last point in the triangle.

Iterators (ADL)

auto begin(triangle& v) -> iterator constexpr noexcept
Returns an iterator to the first point in a triangle.
auto begin(const triangle& v) -> const_iterator constexpr noexcept
Returns a const iterator to the first point in a triangle.
auto cbegin(const triangle& v) -> const_iterator constexpr noexcept
Returns a const iterator to the first point in a triangle.
auto cend(const triangle& v) -> const_iterator constexpr noexcept
Returns a const iterator to the one-past-the-last point in a triangle.
auto end(triangle& v) -> iterator constexpr noexcept
Returns an iterator to the one-past-the-last point in a triangle.
auto end(const triangle& v) -> const_iterator constexpr noexcept
Returns a const iterator to the one-past-the-last point in a triangle.

Point accessors

template <size_t P>
auto get() -> vector_type& constexpr noexcept
Returns a reference to one of the triangle's points.
template <size_t P>
auto get() const -> constvector_type& constexpr noexcept
Returns a reference to one of the triangle's points.
auto operator[](size_t p) -> vector_type& constexpr noexcept
Returns a reference to one of the triangle's points.
auto operator[](size_t p) const -> constvector_type& constexpr noexcept
Returns a reference to one of the triangle's points.

Scalar accessors

auto data() -> scalar_type* constexpr noexcept
Returns a pointer to the first scalar component in the triangle.
auto data() const -> constscalar_type* constexpr noexcept
Returns a pointer to the first scalar component in the triangle.

Friends

template <typename Char, typename Traits>
auto operator<<(std::basic_ostream<Char, Traits>& os, const triangle& tri) -> std::basic_ostream<Char, Traits>&
Writes a triangle out to a text stream.

Function documentation

template <typename Scalar>
template <typename T>
muu::triangle::triangle(const T& obj) constexpr noexcept

Constructs a triangle from an implicitly bit-castable type.

Template parameters
T A bit-castable type.

template <typename Scalar>
static bool muu::triangle::zero(const triangle& tri) constexpr noexcept

Returns true if all the points of a triangle are exactly zero.

template <typename Scalar>
bool muu::triangle::zero() const constexpr noexcept

Returns true if all the points of the triangle are exactly zero.

template <typename Scalar>
template <typename T>
bool muu::triangle::operator!=(const triangle& lhs, const triangle<T>& rhs) constexpr noexcept

Returns true if two triangles are not exactly equal.

template <typename Scalar>
template <typename T>
bool muu::triangle::operator==(const triangle& lhs, const triangle<T>& rhs) constexpr noexcept

Returns true if two triangles are exactly equal.

template <typename Scalar>
static vector_type muu::triangle::centroid(const vector_type& p0, const vector_type& p1, const vector_type& p2) constexpr noexcept

Returns a triangle's centroid point.

template <typename Scalar>
vector_type muu::triangle::centroid() const constexpr noexcept

Returns the triangle's centroid point.