27 #ifndef MLN_ALGEBRA_H_MAT_HH
28 # define MLN_ALGEBRA_H_MAT_HH
45 # include <mln/algebra/mat.hh>
46 # include <mln/algebra/quat.hh>
48 # include <mln/math/pi.hh>
49 # include <mln/util/couple.hh>
60 template <
unsigned d,
typename T>
81 # ifndef MLN_INCLUDE_ONLY
83 template <
unsigned d,
typename T>
86 : mat<d+1, d+1,
T>(mat<d+1, d+1,
T>::Id)
90 template <
unsigned d,
typename T>
92 h_mat<d,T>::h_mat(
const mat<d+1, d+1, T>& x)
100 template <
typename C>
101 void from_to_(
const algebra::h_mat<3,C>& from, algebra::quat& to)
103 C
tr = from(0, 0) + from(1, 1) + from(2, 2) + 1;
107 C s = 0.5 /
sqrt(tr),
109 x = (from(2, 1) - from(1, 2)) * s,
110 y = (from(0, 2) - from(2, 0)) * s,
111 z = (from(1, 0) - from(0, 1)) * s;
113 to = algebra::quat(w, x, y, z);
123 for (
unsigned d = 0; d <= 3; ++d)
124 if (from(d, d) > max)
135 s =
sqrt(1.0 + from(0, 0) - from(1, 1) - from(2, 2)) * 2;
137 y = (from(0, 1) + from(1, 0)) / s;
138 z = (from(0, 2) + from(2, 0)) / s;
139 w = (from(1, 2) + from(2, 1)) / s;
143 s =
sqrt(1.0 + from(1, 1) - from(0, 0) - from(2, 2)) * 2;
144 x = (from(0, 1) + from(1, 0)) / s;
146 z = (from(1, 2) + from(2, 1)) / s;
147 w = (from(0, 2) + from(2, 0)) / s;
151 s =
sqrt(1.0 + from(2, 2) - from(0, 0) - from(1, 1)) * 2;
152 x = (from(0, 2) + from(2, 0)) / s;
153 y = (from(1, 2) + from(2, 1)) / s;
155 w = (from(0, 1) + from(1, 0) ) / s;
166 to = algebra::quat(w, x, y, z);
171 # endif // ! MLN_INCLUDE_ONLY
179 #endif // ! MLN_ALGEBRA_H_MAT_HH