opynsim
Unofficial C++ Documentation
Loading...
Searching...
No Matches
triangle_functions.h
Go to the documentation of this file.
1#pragma once
2
6
7#include <concepts>
8#include <type_traits>
9
10namespace osc
11{
12 // returns `true` if the given three `Vector3`s could be used to form a triangle
13 template<typename T>
14 requires std::is_arithmetic_v<T>
15 constexpr bool can_form_triangle(const Vector<T, 3>& a, const Vector<T, 3>& b, const Vector<T, 3>& c)
16 {
17 return a != b and a != c and b != c; // (this also handles NaNs)
18 }
19
20 template<std::floating_point T>
22 {
23 const Vector<T, 3> ab = b - a;
24 const Vector<T, 3> ac = c - a;
25 return Vector<T, 3>(normalize(cross(ab, ac)));
26 }
27
29 {
30 return triangle_normal(t.p0, t.p1, t.p2);
31 }
32}
Definition vector.h:63
Definition custom_decoration_generator.h:5
Vector< T, 3 > triangle_normal(const Vector< T, 3 > &a, const Vector< T, 3 > &b, const Vector< T, 3 > &c)
Definition triangle_functions.h:21
constexpr bool can_form_triangle(const Vector< T, 3 > &a, const Vector< T, 3 > &b, const Vector< T, 3 > &c)
Definition triangle_functions.h:15
constexpr U to(T &&value)
Definition conversion.h:56
Vector< T, N > normalize(const Vector< T, N > &v)
Definition geometric_functions.h:74
and
Definition algorithms.h:158
constexpr CoordinateDirection cross(CoordinateDirection x, CoordinateDirection y)
Definition coordinate_direction.h:117
Definition triangle.h:9