26 #include "polynomial.h" 27 #include "quaternion.h" 30 #define POLHEMUS_POS_X 1284.6 31 #define POLHEMUS_POS_Y 1319.2 32 #define POLHEMUS_POS_Z -553.0 33 #define KOORD_OFFSET_X -16.0 34 #define KOORD_OFFSET_Y 65.0 35 #define KOORD_OFFSET_Z 0.0 111 double distf=0,distw=0;
113 for (
int x=0;
x<3;
x++)
114 for (
int y=0;
y<3;
y++)
121 distf=distf*distw/countCoord/countCoord/10;
124 for (
int x=0;
x<3;
x++)
125 for (
int y=0;
y<3;
y++)
130 N[0][0]=
S[0][0]+
S[1][1]+
S[2][2];
N[0][1]=S[1][2]-S[2][1];
N[0][2]=S[2][0]-S[0][2];
N[0][3]=S[0][1]-S[1][0];
131 N[1][0]=S[1][2]-S[2][1];
N[1][1]=S[0][0]-S[1][1]-S[2][2];
N[1][2]=S[0][1]+S[1][0];
N[1][3]=S[2][0]+S[0][2];
132 N[2][0]=S[2][0]-S[0][2];
N[2][1]=S[0][1]+S[1][0];
N[2][2]=-S[0][0]+S[1][1]-S[2][2];
N[2][3]=S[1][2]+S[2][1];
133 N[3][0]=S[0][1]-S[1][0];
N[3][1]=S[2][0]+S[0][2];
N[3][2]=S[1][2]+S[2][1];
N[3][3]=-S[0][0]-S[1][1]+S[2][2];
137 c2= (
N[0][0]*
N[2][2] -
sqr(
N[0][2])) + (
N[1][1]*
N[2][2] -
sqr(
N[1][2])) +
138 (
N[0][0]*
N[3][3] -
sqr(
N[0][3])) + (
N[1][1]*
N[3][3] -
sqr(
N[1][3])) +
139 (
N[2][2]*
N[3][3] +
sqr(
N[2][3])) + (
N[0][0]*
N[1][1] -
sqr(
N[0][1]));
141 c1 = -
N[1][1]*(
N[2][2]*
N[3][3] -
sqr(
N[2][3])) +
N[1][2]*(
N[3][3]*
N[1][2] -
N[2][3]*
N[1][3]) - N[1][3]*(N[1][2]*N[2][3] - N[2][2]*N[1][3])
142 -N[0][0]*(N[2][2]*N[3][3] -
sqr(N[2][3])) + N[0][2]*(N[3][3]*N[0][2] - N[2][3]*N[0][3]) - N[0][3]*(N[2][3]*N[0][2] - N[2][2]*N[0][3])
143 -N[0][0]*(N[1][1]*N[3][3] -
sqr(N[1][3])) + N[0][1]*(N[3][3]*N[0][1] - N[1][3]*N[0][3]) - N[0][3]*(N[0][1]*N[1][3] - N[1][1]*N[0][3])
144 -N[0][0]*(N[1][1]*N[2][2] -
sqr(N[1][2])) + N[0][1]*(N[2][2]*N[0][1] - N[1][2]*N[0][2]) - N[0][2]*(N[0][1]*N[1][2] - N[1][1]*N[0][2]);
146 c0 = (N[0][0]*N[1][1] -
sqr(N[0][1]))*(N[2][2]*N[3][3] -
sqr(N[2][3])) + (N[0][1]*N[0][2] - N[0][0]*N[1][2])*(N[1][2]*N[3][3] - N[2][3]*N[1][3])
147 + (N[0][0]*N[1][3] - N[0][1]*N[0][3]) * (N[1][2]*N[2][3] - N[2][2]*N[1][3]) + (N[0][1]*N[1][2] - N[1][1]*N[0][2])*(N[0][2]*N[3][3] - N[2][3]*N[0][3])
148 + (N[1][1]*N[0][3] - N[0][1]*N[1][3]) * (N[0][2]*N[2][3] - N[2][2]*N[0][3]) +
sqr(N[0][2]*N[1][3] - N[1][2]*N[0][3]);
159 a[0]=x1;a[1]=x2;a[2]=x3;a[3]=x4;
160 printf(
"Solutions for Lamda (%d): ",c);
161 for (i=0;i<c;i++) printf(
"%f ",a[i]);
163 if (c!=0)
l=a[0];
else l=-HUGE_VAL;
170 printf (
"Error after find_max_lambda: %d\n",
ERR);
174 for (
int i=0;i<4;i++)
183 for (
int i=0;i<4;i++)
184 N[to][i]+=
N[from][i]*value;
191 case 0:q->
r=value;
break;
192 case 1:q->
i=value;
break;
193 case 2:q->
j=value;
break;
194 case 3:q->
k=value;
break;
206 for (
int i=0;i<4;i++)
208 for (
int i=0;i<4;i++)
209 for (
int j=0;j<4;j++)
213 for (
int i=0;i<4;i++)
215 for (
int k=0;k<4;k++)
221 if (j>=0) {
setQuat(j,&solution,1);
return;}
223 for (
int i1=0;i1<4;i1++)
224 for (
int j=0;j<3;j++)
227 for (
int k=1;k<4;k++)
242 for (
int i2=1;i2<4;i2++)
245 double a=-(N[m][2]*N[0][0]-N[0][2]*N[m][0])/(N[0][0]*N[m][1]-N[m][0]*N[0][1]);
246 double b= (N[m][2]*N[0][1]-N[0][2]*N[m][1])/(N[0][0]*N[m][1]-N[m][0]*N[0][1]);
251 case 1:n=2;p=3;
break;
252 case 2:n=1;p=3;
break;
253 case 3:n=1;p=2;
break;
267 for (
int i=0;i<4;i++)
274 for (
int i=1;i<4;i++)
280 for (
int i=2;i<4;i++)
286 for (
int i=0;i<2;i++)
292 solution.
j=(0.5*
N[2][3]/
N[2][2]+0.5*
N[3][3]/
N[3][2]);
293 solution.
i=((
N[1][3]-solution.
j*
N[1][2])/
N[1][1]);
294 solution.
r=((
N[0][3]-solution.
j*
N[0][2]-solution.
i*
N[0][1])/
N[0][0]);
307 printf(
"Scale is %f\n",
scale);
325 printf(
"Transformation Vector is:%f %f %f\n",
trans[0],
trans[1],
trans[2]);
328 void transform_point(
double xi,
double yi,
double zi,
double* xo,
double* yo,
double* zo)
348 for (
int i=0;i<6;i++)
366 solution.
i=-solution.
i;
367 solution.
j=-solution.
j;
368 solution.
k=-solution.
k;
369 printf(
"Rotation Quaternion:");
377 cout <<
"Calibrated: " <<
calibrated <<
"(error: " <<
ERR <<
")\n";
396 printf(
"Not calibrated call of transform\n");
409 #if transformCoords_test 411 int main(
int argc,
char **argv)
419 fprintf(stderr,
"Testing transformCoords\n");
quaternion qadd(quaternion a, quaternion b)
int main(int argc, char **argv)
quaternion qscale(double s, quaternion a)
TFSIMD_FORCE_INLINE const tfScalar & y() const
quaternion qsub(quaternion a, quaternion b)
TFSIMD_FORCE_INLINE const tfScalar & x() const
quaternion qmul(quaternion a, quaternion b)
TFSIMD_FORCE_INLINE const tfScalar & z() const
quaternion qinv(quaternion a)
void qprint(quaternion c)
int solve_biquadratic(double a4, double a3, double a2, double a1, double a0, double *x1, double *x2, double *x3, double *x4)