33 #ifndef __VMML__JACOBI_SOLVER__HPP__
34 #define __VMML__JACOBI_SOLVER__HPP__
36 #include <vmmlib/vmmlib.hpp>
58 template <
typename T >
59 bool solve_jacobi_3x3(
63 size_t& rotationCount )
69 for (
size_t i = 0; i < 3; ++i )
71 b[i] = d[i] = a( i,i );
74 T t, theta, s, c, tau;
76 for (
size_t i = 1; i <= 150; ++i )
79 for (
size_t ip = 0; ip < 2; ++ip )
81 for (
size_t iq = ip + 1; iq < 3; ++iq )
83 sm += fabs( a( iq, ip ) );
91 T tresh = ( i < 4 ) ? 0.2 * sm / 9.0 : 0.0;
93 for ( ssize_t ip = 0; ip < 2; ++ip )
95 for ( ssize_t iq = ip + 1; iq < 3; ++iq )
97 T g = 100.0 * fabs( a( iq,ip ) );
102 && fabs( d[ip] ) + g == fabs( d[ip] )
103 && fabs( d[iq] ) + g == fabs( d[iq] )
110 if ( fabs( a( iq, iq ) ) > tresh )
113 if ( fabs( h ) + g == fabs( h ) )
116 t = ( a( iq, ip ) ) / h;
122 if( a( iq, ip ) != 0.0 )
123 theta = 0.5 * h / ( a( iq, ip ) );
126 t = 1.0 / ( fabs( theta ) + sqrt( 1.0 + theta * theta ) );
130 c = 1.0 / sqrt( 1 + t * t );
132 tau = s / ( 1.0 + c );
140 for ( ssize_t j = 0; j <= ip - 1; ++j )
144 a( ip, j ) = g - s * ( h + g * tau );
145 a( iq, j ) = h + s * ( g - h * tau );
147 for ( ssize_t j = ip + 1; j <= iq - 1; ++j )
151 a( j, ip ) = g - s * ( h + g * tau );
152 a( iq, j ) = h + s * ( g - h * tau );
154 for (
size_t j = iq + 1; j < 3; ++j )
158 a( j, ip ) = g - s * ( h + g * tau );
159 a( j, iq ) = h + s * ( g - h * tau );
161 for (
size_t j = 0; j < 3; ++j )
165 v( ip, j ) = g - s * ( h + g * tau );
166 v( iq, j ) = h + s * ( g - h * tau );
174 for (
size_t ip = 0; ip < 3; ++ip )