emlabcpp
modern opinionated embedded C++ library
triangle.h
Go to the documentation of this file.
1 
24 #pragma once
25 
30 
31 namespace emlabcpp
32 {
33 
34 template < std::size_t N >
36 
38 {
39  vector< 3 > const ab = tri[0] - tri[1];
40  vector< 3 > const ac = tri[0] - tri[2];
41  vector< 3 > const normal = normalized( cross_product( ab, ac ) );
42  vector< 3 > p_ab = cross_product( normal, ab );
43  vector< 3 > p_ac = cross_product( normal, ac );
44  vector< 3 > c_ac = ( vector_cast( tri[0] ) + vector_cast( tri[2] ) ) / 2;
45  vector< 3 > c_ab = ( vector_cast( tri[0] ) + vector_cast( tri[1] ) ) / 2;
46 
47  float k;
48 
49  k = p_ab[0] * ( c_ab[1] - c_ac[1] ) + p_ab[1] * ( c_ac[0] - c_ab[0] );
50  //-------------------------------------------------------------------
51  k /= ( p_ab[0] * p_ac[1] - p_ac[0] * p_ab[1] );
52 
53  return point_cast( c_ac + k * p_ac );
54 }
55 
56 constexpr vector< 3 > normal_of( triangle< 3 > const& tri )
57 {
58  return cross_product( tri[0] - tri[1], tri[0] - tri[2] );
59 }
60 
61 constexpr triangle< 3 > transform( triangle< 3 > const& t, pose const& transformation )
62 {
63  return triangle< 3 >{
64  transform( t[0], transformation ),
65  transform( t[1], transformation ),
66  transform( t[2], transformation ) };
67 }
68 
69 template < std::size_t N >
70 constexpr triangle< N > scale( triangle< N > const& t, point< N > const& scales )
71 {
72  return triangle< N >{ t[0] * scales, t[1] * scales, t[2] * scales };
73 }
74 
75 } // namespace emlabcpp
Definition: simplex.h:39
Definition: vector.h:33
MIT License.
Definition: impl.h:31
constexpr vector< 3 > normal_of(triangle< 3 > const &tri)
Definition: triangle.h:56
constexpr point< N > point_cast(vector< N > const &v)
Definition: point.h:61
constexpr triangle< N > scale(triangle< N > const &t, point< N > const &scales)
Definition: triangle.h:70
point< 3 > get_triangle_sphere_center(triangle< 3 > const &tri)
Definition: triangle.h:37
constexpr vector< 3 > cross_product(vector< 3 > const &a, vector< 3 > const &b)
Calculates cross product between points A and B.
Definition: vector.h:66
constexpr Derived normalized(vec_point_base< Derived, N > const &a)
Calculates normalized version of A, this means that length(A) equals to 1.
Definition: vec_point_base.h:211
constexpr point< 3 > transform(point< 3 > const &a, pose const &transformation)
Point A is rotated based on 'transformation' orientation and than moved based on 'transformation' pos...
Definition: pose.h:140
constexpr vector< N > vector_cast(point< N > const &p)
Definition: point.h:67
represents orientation and position in 3D space
Definition: pose.h:55