Added void insertion to arctohgt
[tecorrec.git] / geo / tcAffineTransform.cpp
blob4bedb62bc9a0e973d34537f9ba7795bf6969ba7c
1 /***************************************************************************
2 * This file is part of Tecorrec. *
3 * Copyright 2008 James Hogan <james@albanarts.com> *
4 * *
5 * Tecorrec is free software: you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation, either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * Tecorrec is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with Tecorrec. If not, write to the Free Software Foundation, *
17 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
18 ***************************************************************************/
20 /**
21 * @file tcAffineTransform.cpp
22 * @brief Affine transformation between 2d linear coordinate spaces.
25 #include "tcAffineTransform.h"
27 #include <gdal_priv.h>
29 /// Find the inverse.
30 template <>
31 tcAffineTransform2<double> tcAffineTransform2<double>::inverse() const
33 /// @todo Implement independently of GDAL
35 * [a,b,c;d,e,f].[1;x;y] = [n;t]
36 * n = a + b*x + c*y (1)
37 * t = d + e*x + f*y (2)
38 * (rearrange to make x subject of (2))
39 * x = (t - d - f*y)/e (3)
40 * (substitude (3) into (1))
41 * n = a + b*(t - d - f*y)/e + c*y (4)
42 * (rearrange to make y subject of (4))
43 * n = a + b*(t - d)/e - b*f*y/e + c*y
44 * n = a + b*(t - d)/e + y*(c - b*f/e)
45 * y = (n - a + b*(d - t)/e ) / (c - b*f/e)
46 * y = (n + (b*d/e - a) - t*b/e ) / (c - b*f/e)
47 * (rearrange to make y subject of ..)
48 * ..
49 * [1;x;y] = [g,h,i;j,k,m].[n;t]
50 * j = (b*d/e - a) / (c - b*f/e)
51 * k = 1 / (c - b*f/e)
52 * m = - b/(e*c - b*f)
54 tcAffineTransform2 result;
55 GDALInvGeoTransform((double*)&m_transform[0][0], result);
56 return result;