9 #include <gsl/gsl_linalg.h>
13 namespace AlignmentSubsystem
19 return new SVDMathPlugin;
29 return "SVD Math Plugin";
32 void SVDMathPlugin::CalculateTransformMatrices(
const TelescopeDirectionVector &Alpha1,
33 const TelescopeDirectionVector &Alpha2,
34 const TelescopeDirectionVector &Alpha3,
35 const TelescopeDirectionVector &Beta1,
36 const TelescopeDirectionVector &Beta2,
37 const TelescopeDirectionVector &Beta3, gsl_matrix *pAlphaToBeta,
38 gsl_matrix *pBetaToAlpha)
43 gsl_matrix *pAlphaMatrix = gsl_matrix_alloc(3, 3);
44 gsl_matrix_set(pAlphaMatrix, 0, 0, Alpha1.x);
45 gsl_matrix_set(pAlphaMatrix, 1, 0, Alpha1.y);
46 gsl_matrix_set(pAlphaMatrix, 2, 0, Alpha1.z);
47 gsl_matrix_set(pAlphaMatrix, 0, 1, Alpha2.x);
48 gsl_matrix_set(pAlphaMatrix, 1, 1, Alpha2.y);
49 gsl_matrix_set(pAlphaMatrix, 2, 1, Alpha2.z);
50 gsl_matrix_set(pAlphaMatrix, 0, 2, Alpha3.x);
51 gsl_matrix_set(pAlphaMatrix, 1, 2, Alpha3.y);
52 gsl_matrix_set(pAlphaMatrix, 2, 2, Alpha3.z);
53 Dump3x3(
"AlphaMatrix", pAlphaMatrix);
54 gsl_matrix *pBetaMatrix = gsl_matrix_alloc(3, 3);
55 gsl_matrix_set(pBetaMatrix, 0, 0, Beta1.x);
56 gsl_matrix_set(pBetaMatrix, 1, 0, Beta1.y);
57 gsl_matrix_set(pBetaMatrix, 2, 0, Beta1.z);
58 gsl_matrix_set(pBetaMatrix, 0, 1, Beta2.x);
59 gsl_matrix_set(pBetaMatrix, 1, 1, Beta2.y);
60 gsl_matrix_set(pBetaMatrix, 2, 1, Beta2.z);
61 gsl_matrix_set(pBetaMatrix, 0, 2, Beta3.x);
62 gsl_matrix_set(pBetaMatrix, 1, 2, Beta3.y);
63 gsl_matrix_set(pBetaMatrix, 2, 2, Beta3.z);
64 Dump3x3(
"BetaMatrix", pBetaMatrix);
71 GslRetcode = gsl_matrix_transpose(pAlphaMatrix);
74 gsl_matrix *pIntermediateMatrix1 = gsl_matrix_alloc(3, 3);
78 gsl_matrix *pV = gsl_matrix_alloc(3, 3);
79 gsl_vector *pS = gsl_vector_alloc(3);
80 gsl_vector *pWork = gsl_vector_alloc(3);
81 GslRetcode = gsl_linalg_SV_decomp(pIntermediateMatrix1, pV, pS, pWork);
86 gsl_matrix *pDiagonal = gsl_matrix_calloc(3, 3);
87 gsl_matrix_set(pDiagonal, 0, 0, 1);
88 gsl_matrix_set(pDiagonal, 1, 1, 1);
92 gsl_matrix_transpose(pV);
93 gsl_matrix *pIntermediateMatrix2 = gsl_matrix_alloc(3, 3);
97 Dump3x3(
"AlphaToBeta", pAlphaToBeta);
99 if (
nullptr != pBetaToAlpha)
107 gsl_matrix_set_identity(pBetaToAlpha);
108 ASSDEBUG(
"CalculateTransformMatrices - AlphaToBeta matrix is singular!");
110 "Calculated Celestial to Telescope transformation matrix is singular (not a true transform).");
113 Dump3x3(
"BetaToAlpha", pBetaToAlpha);
117 gsl_matrix_free(pIntermediateMatrix1);
120 gsl_vector_free(pWork);
121 gsl_matrix_free(pDiagonal);
122 gsl_matrix_free(pIntermediateMatrix2);
123 gsl_matrix_free(pBetaMatrix);
124 gsl_matrix_free(pAlphaMatrix);