#include <muu/triangle.h>
template <typename Scalar>
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
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
template <typename T>
Constructs a triangle from an implicitly bit-castable type.
Template parameters | |
---|---|
T | A bit-castable type. |
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
template <typename T>
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
template <typename T>
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.