bazar  1.3.1
linear_systems.cpp
Go to the documentation of this file.
1 /*
2 Copyright 2005, 2006 Computer Vision Lab,
3 Ecole Polytechnique Federale de Lausanne (EPFL), Switzerland.
4 All rights reserved.
5 
6 This file is part of BazAR.
7 
8 BazAR is free software; you can redistribute it and/or modify it under the
9 terms of the GNU General Public License as published by the Free Software
10 Foundation; either version 2 of the License, or (at your option) any later
11 version.
12 
13 BazAR is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
15 PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 
17 You should have received a copy of the GNU General Public License along with
18 BazAR; if not, write to the Free Software Foundation, Inc., 51 Franklin
19 Street, Fifth Floor, Boston, MA 02110-1301, USA
20 */
21 #include "linear_systems.h"
22 #include "linear_algebra.h"
23 
24 bool solve_ls(double A11, double A12, double A13, double & x1, double B1,
25  double A21, double A22, double A23, double & x2, double B2,
26  double A31, double A32, double A33, double & x3, double B3)
27 {
28  double det = gfla_det(A11, A12, A13,
29  A21, A22, A23,
30  A31, A32, A33);
31 
32  x1 = x2 = x3 = 0;
33  if (det == 0) return false;
34 
35  double inv_det = 1. / det;
36 
37  x1 = inv_det * (gfla_det(A22, A23, A32, A33) * B1 + gfla_det(A13, A12, A33, A32) * B2 + gfla_det(A12, A13, A22, A23) * B3);
38  x2 = inv_det * (gfla_det(A23, A21, A33, A31) * B1 + gfla_det(A11, A13, A31, A33) * B2 + gfla_det(A13, A11, A23, A21) * B3);
39  x3 = inv_det * (gfla_det(A21, A22, A31, A32) * B1 + gfla_det(A12, A11, A32, A31) * B2 + gfla_det(A11, A12, A21, A22) * B3);
40 
41  return true;
42 }
43