File: BuiltInMathPlugin.cpp

package info (click to toggle)
indi 2.1.9%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 15,888 kB
  • sloc: cpp: 217,447; ansic: 31,363; xml: 1,195; sh: 311; makefile: 13
file content (95 lines) | stat: -rw-r--r-- 3,547 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/// \file BuiltInMathPlugin.cpp
/// \author Roger James
/// \date 13th November 2013

#include "BuiltInMathPlugin.h"

#include "DriverCommon.h"

namespace INDI
{
namespace AlignmentSubsystem
{
// Private methods

void BuiltInMathPlugin::CalculateTransformMatrices(const TelescopeDirectionVector &Alpha1,
        const TelescopeDirectionVector &Alpha2,
        const TelescopeDirectionVector &Alpha3,
        const TelescopeDirectionVector &Beta1,
        const TelescopeDirectionVector &Beta2,
        const TelescopeDirectionVector &Beta3, gsl_matrix *pAlphaToBeta,
        gsl_matrix *pBetaToAlpha)
{
    // Derive the Actual to Apparent transformation matrix
    gsl_matrix *pAlphaMatrix = gsl_matrix_alloc(3, 3);
    gsl_matrix_set(pAlphaMatrix, 0, 0, Alpha1.x);
    gsl_matrix_set(pAlphaMatrix, 1, 0, Alpha1.y);
    gsl_matrix_set(pAlphaMatrix, 2, 0, Alpha1.z);
    gsl_matrix_set(pAlphaMatrix, 0, 1, Alpha2.x);
    gsl_matrix_set(pAlphaMatrix, 1, 1, Alpha2.y);
    gsl_matrix_set(pAlphaMatrix, 2, 1, Alpha2.z);
    gsl_matrix_set(pAlphaMatrix, 0, 2, Alpha3.x);
    gsl_matrix_set(pAlphaMatrix, 1, 2, Alpha3.y);
    gsl_matrix_set(pAlphaMatrix, 2, 2, Alpha3.z);

    Dump3x3("AlphaMatrix", pAlphaMatrix);

    gsl_matrix *pBetaMatrix = gsl_matrix_alloc(3, 3);
    gsl_matrix_set(pBetaMatrix, 0, 0, Beta1.x);
    gsl_matrix_set(pBetaMatrix, 1, 0, Beta1.y);
    gsl_matrix_set(pBetaMatrix, 2, 0, Beta1.z);
    gsl_matrix_set(pBetaMatrix, 0, 1, Beta2.x);
    gsl_matrix_set(pBetaMatrix, 1, 1, Beta2.y);
    gsl_matrix_set(pBetaMatrix, 2, 1, Beta2.z);
    gsl_matrix_set(pBetaMatrix, 0, 2, Beta3.x);
    gsl_matrix_set(pBetaMatrix, 1, 2, Beta3.y);
    gsl_matrix_set(pBetaMatrix, 2, 2, Beta3.z);

    Dump3x3("BetaMatrix", pBetaMatrix);

    // Use the quick and dirty method
    // This can result in matrices which are not true transforms
    gsl_matrix *pInvertedAlphaMatrix = gsl_matrix_alloc(3, 3);

    if (!MatrixInvert3x3(pAlphaMatrix, pInvertedAlphaMatrix))
    {
        // pAlphaMatrix is singular and therefore is not a true transform
        // and cannot be inverted. This probably means it contains at least
        // one row or column that contains only zeroes
        gsl_matrix_set_identity(pInvertedAlphaMatrix);
        ASSDEBUG("CalculateTransformMatrices - Alpha matrix is singular!");
        IDMessage(nullptr, "Alpha matrix is singular and cannot be inverted.");
    }
    else
    {
        MatrixMatrixMultiply(pBetaMatrix, pInvertedAlphaMatrix, pAlphaToBeta);

        Dump3x3("AlphaToBeta", pAlphaToBeta);

        if (nullptr != pBetaToAlpha)
        {
            // Invert the matrix to get the Apparent to Actual transform
            if (!MatrixInvert3x3(pAlphaToBeta, pBetaToAlpha))
            {
                // pAlphaToBeta is singular and therefore is not a true transform
                // and cannot be inverted. This probably means it contains at least
                // one row or column that contains only zeroes
                gsl_matrix_set_identity(pBetaToAlpha);
                ASSDEBUG("CalculateTransformMatrices - AlphaToBeta matrix is singular!");
                IDMessage(
                    nullptr,
                    "Calculated Celestial to Telescope transformation matrix is singular (not a true transform).");
            }

            Dump3x3("BetaToAlpha", pBetaToAlpha);
        }
    }

    // Clean up
    gsl_matrix_free(pInvertedAlphaMatrix);
    gsl_matrix_free(pBetaMatrix);
    gsl_matrix_free(pAlphaMatrix);
}

} // namespace AlignmentSubsystem
} // namespace INDI