summaryrefslogtreecommitdiffstats
path: root/jni/feature_mos/src/mosaic/trsMatrix.cpp
blob: 5fc6a86b3c47bcf5b47e699f867370dd67f185ad (plain)
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
/*
 * Copyright (C) 2011 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

// trsMatrix.cpp
// $Id: trsMatrix.cpp,v 1.9 2011/06/17 13:35:48 mbansal Exp $

#include "stdio.h"
#include <math.h>
#include "trsMatrix.h"

void mult33d(double a[3][3], double b[3][3], double c[3][3])
{
    a[0][0] = b[0][0]*c[0][0] + b[0][1]*c[1][0] + b[0][2]*c[2][0];
    a[0][1] = b[0][0]*c[0][1] + b[0][1]*c[1][1] + b[0][2]*c[2][1];
    a[0][2] = b[0][0]*c[0][2] + b[0][1]*c[1][2] + b[0][2]*c[2][2];
    a[1][0] = b[1][0]*c[0][0] + b[1][1]*c[1][0] + b[1][2]*c[2][0];
    a[1][1] = b[1][0]*c[0][1] + b[1][1]*c[1][1] + b[1][2]*c[2][1];
    a[1][2] = b[1][0]*c[0][2] + b[1][1]*c[1][2] + b[1][2]*c[2][2];
    a[2][0] = b[2][0]*c[0][0] + b[2][1]*c[1][0] + b[2][2]*c[2][0];
    a[2][1] = b[2][0]*c[0][1] + b[2][1]*c[1][1] + b[2][2]*c[2][1];
    a[2][2] = b[2][0]*c[0][2] + b[2][1]*c[1][2] + b[2][2]*c[2][2];
}


// normProjMat33d
// m = input matrix
// return: result if successful
int normProjMat33d(double m[3][3])
{
    double m22;

    if(m[2][2] == 0.0)
        {
        return 0;
}

    m[0][0] /= m[2][2];
    m[0][1] /= m[2][2];
    m[0][2] /= m[2][2];
    m[1][0] /= m[2][2];
    m[1][1] /= m[2][2];
    m[1][2] /= m[2][2];
    m[2][0] /= m[2][2];
    m[2][1] /= m[2][2];
    m[2][2] = 1.0;

    return 1;
}

// det33d
// m = input matrix
// returns: determinant
double det33d(const double m[3][3])
{
    double result;

    result  = m[0][0] * (m[1][1] * m[2][2] - m[1][2] * m[2][1]);
    result += m[0][1] * (m[1][2] * m[2][0] - m[1][0] * m[2][2]);
    result += m[0][2] * (m[1][0] * m[2][1] - m[1][1] * m[2][0]);

    return result;
}

// inv33d
//
void inv33d(const double m[3][3], double out[3][3])
{
    double det = det33d(m);

    out[0][0] = (m[1][1]*m[2][2] - m[1][2]*m[2][1]) / det;
    out[1][0] = (m[1][2]*m[2][0] - m[1][0]*m[2][2]) / det;
    out[2][0] = (m[1][0]*m[2][1] - m[1][1]*m[2][0]) / det;

    out[0][1] = (m[0][2]*m[2][1] - m[0][1]*m[2][2]) / det;
    out[1][1] = (m[0][0]*m[2][2] - m[0][2]*m[2][0]) / det;
    out[2][1] = (m[0][1]*m[2][0] - m[0][0]*m[2][1]) / det;

    out[0][2] = (m[0][1]*m[1][2] - m[0][2]*m[1][1]) / det;
    out[1][2] = (m[0][2]*m[1][0] - m[0][0]*m[1][2]) / det;
    out[2][2] = (m[0][0]*m[1][1] - m[0][1]*m[1][0]) / det;
}