7 #ifndef __geometry_MatrixSqrt_h__ 8 #define __geometry_MatrixSqrt_h__ 10 #define FE_MSQ_DEBUG FALSE 11 #define FE_MSQ_VERIFY (FE_CODEGEN<=FE_DEBUG) 12 #define FE_MSQ_MAX_ERROR_R 1e-3 13 #define FE_MSQ_MAX_ERROR_T 1e-2 18 #define FE_MSQ_METHOD 0 39 template <
typename MATRIX>
47 void solve(MATRIX& B,
const MATRIX& A)
const;
49 void setIterations(U32 iterations) { m_iterations=iterations; }
55 template <
typename MATRIX>
59 feLog(
"\nA\n%s\n",c_print(A));
66 const BWORD fix0=(fabs(AA(0,0)+1)<1e-3);
67 const BWORD fix1=(fabs(AA(1,1)+1)<1e-3);
68 const BWORD fix2=(fabs(AA(2,2)+1)<1e-3);
69 const BWORD fix=(fix0 || fix1 || fix2);
79 quat.computeAngleAxis(radians,axis);
82 const F64 tinyAngle=tiny*radians;
88 translate(correction,forwardT);
94 translate(tweak,reverseT);
108 feLog(
"\ntweak\n%s\n",c_print(tweak));
109 feLog(
"\ncorrection\n%s\n",c_print(correction));
124 #elif FE_MSQ_METHOD==1 140 for(iteration=0;iteration<m_iterations;iteration++)
146 feLog(
"\n>>>> iteration %d\nY\n%s\nZ\n%s\n",iteration,
149 feLog(
"Y*Y\n%s\nZ*Z\n%s\n",
150 c_print(Y[last]*Y[last]),
151 c_print(Z[last]*Z[last]));
166 feLog(
"Y+invZ\n%s\nZ+invY\n%s\n",
167 c_print(Y[last]+invZ),
168 c_print(Z[last]+invY));
171 Y[current]=0.5*(Y[last]+invZ);
172 Z[current]=0.5*(Z[last]+invY);
174 #elif FE_MSQ_METHOD==1 185 Y[current]= -1*Y[last]*invZ*Y[last];
186 Z[current]=Z[last]+2*Y[current];
192 MATRIX I3ZY=I3-Z[last]*Y[last];
194 Y[current]=0.5*Y[last]*I3ZY;
195 Z[current]=0.5*I3ZY*Z[last];
202 MATRIX& R=Y[current];
203 #elif FE_MSQ_METHOD==1 205 MATRIX R=0.25*Z[current];
209 MATRIX& R=Y[current];
214 feLog(
"\nA\n%s\n",c_print(A));
217 feLog(
"\nA'\n%s\n",c_print(AA));
219 feLog(
"\nB'\n%s\nB'*B'\n%s\n",c_print(R),c_print(R*R));
227 feLog(
"\ncorrection\n%s\n",c_print(correction));
228 feLog(
"\ncorrected\n%s\n",c_print(B));
229 feLog(
"\nsquared\n%s\n",c_print(B*B));
242 for(U32 m=0;m<width(diff);m++)
245 for(n=0;n<height(diff)-1;n++)
247 if(FE_INVALID_SCALAR(diff(m,n)))
251 sumR+=fabs(diff(m,n));
253 if(FE_INVALID_SCALAR(diff(m,n)))
257 sumT+=fabs(diff(m,n));
260 #if FE_MSQ_VERIFY && FE_MSQ_DEBUG 261 feLog(
"\ndiff\n%s\ncomponent sumR=%.6G\n",c_print(diff),sumR);
264 if(invalid || sumR>FE_MSQ_MAX_ERROR_R || sumT>FE_MSQ_MAX_ERROR_T)
266 feLog(
"MatrixSqrt< %s >::solve" 267 " error of %.6G,%.6G exceeded limit of %.6G,%.6G\n",
268 FE_TYPESTRING(MATRIX).c_str(),
269 sumR,sumT,FE_MSQ_MAX_ERROR_R,FE_MSQ_MAX_ERROR_T);
270 feLog(
"\nA'\n%s\n",c_print(AA));
271 feLog(
"\nB'\n%s\nB'*B'\n%s\n",c_print(R),c_print(R*R));
273 feX(
"MatrixSqrt<>::solve",
"failed to converge");
kernel
Definition: namespace.dox:3
Matrix< 4, 4, T > & invert(Matrix< 4, 4, T > &a_inverted, const Matrix< 4, 4, T > &a_matrix)
4x4 full matrix inversion
Definition: Matrix.h:1033
General template for fixed size numeric matrices.
Definition: Matrix.h:42
Dense vector - size fixed by template.
Definition: Vector.h:19
solve A=B*B for B, given A
Definition: MatrixSqrt.h:40
Four-dimensional complex number.
Definition: Quaternion.h:32