29 #include <jama/jama_svd.h> 46 p_x = p_y = p_xp = p_yp = 0.0;
63 p_invmat = invert(p_matrix);
64 p_x = p_y = p_xp = p_yp = 0.0;
77 for(
int i = 0 ; i < ident.dim2() ; i++) {
87 void Affine::Identity() {
88 p_matrix = getIdentity();
89 p_invmat = getIdentity();
106 void Affine::Solve(
const double x[],
const double y[],
107 const double xp[],
const double yp[],
int n) {
115 for(
int i = 0; i < n; i++) {
116 vector<double> coord(2);
134 p_matrix[2][0] = 0.0;
135 p_matrix[2][1] = 0.0;
136 p_matrix[2][2] = 1.0;
139 p_invmat = invert(p_matrix);
148 void Affine::Translate(
double tx,
double ty) {
153 p_matrix = TNT::matmult(trans, p_matrix);
157 p_invmat = TNT::matmult(p_invmat, trans);
165 void Affine::Rotate(
double angle) {
168 double angleRadians = angle *
Isis::PI / 180.0;
169 rot[0][0] = cos(angleRadians);
170 rot[0][1] = -sin(angleRadians);
171 rot[1][0] = sin(angleRadians);
172 rot[1][1] = cos(angleRadians);
173 p_matrix = TNT::matmult(rot, p_matrix);
175 angleRadians = -angleRadians;
176 rot[0][0] = cos(angleRadians);
177 rot[0][1] = -sin(angleRadians);
178 rot[1][0] = sin(angleRadians);
179 rot[1][1] = cos(angleRadians);
180 p_invmat = TNT::matmult(p_invmat, rot);
188 void Affine::Scale(
double scaleFactor) {
190 scale[0][0] = scaleFactor;
191 scale[1][1] = scaleFactor;
192 p_matrix = TNT::matmult(scale, p_matrix);
195 p_invmat = invert(p_matrix);
205 void Affine::Compute(
double x,
double y) {
208 p_xp = p_matrix[0][0] * x + p_matrix[0][1] * y + p_matrix[0][2];
209 p_yp = p_matrix[1][0] * x + p_matrix[1][1] * y + p_matrix[1][2];
219 void Affine::ComputeInverse(
double xp,
double yp) {
222 p_x = p_invmat[0][0] * xp + p_invmat[0][1] * yp + p_invmat[0][2];
223 p_y = p_invmat[1][0] * xp + p_invmat[1][1] * yp + p_invmat[1][2];
234 vector<double> Affine::Coefficients(
int var) {
236 vector <double> coef;
237 coef.push_back(p_matrix[index][0]);
238 coef.push_back(p_matrix[index][1]);
239 coef.push_back(p_matrix[index][2]);
251 vector<double> Affine::InverseCoefficients(
int var) {
253 vector <double> coef;
254 coef.push_back(p_invmat[index][0]);
255 coef.push_back(p_invmat[index][1]);
256 coef.push_back(p_invmat[index][2]);
265 void Affine::checkDims(
const AMatrix &am)
const {
266 if((am.dim1() != 3) && (am.dim2() != 3)) {
268 mess <<
"Affine matrices must be 3x3 - this one is " << am.dim1()
290 JAMA::SVD<double> svd(a);
298 for(
int i = 0; i < invS.dim1(); i++) {
299 if(invS[i][i] == 0.0) {
300 string msg =
"Affine transform not invertible";
303 invS[i][i] = 1.0 / invS[i][i];
309 AMatrix transU(U.dim2(), U.dim1());
310 for(
int r = 0; r < U.dim1(); r++) {
311 for(
int c = 0; c < U.dim2(); c++) {
312 transU[c][r] = U[r][c];
317 AMatrix VinvS = TNT::matmult(V, invS);
318 return (TNT::matmult(VinvS, transU));
const double PI
The mathematical constant PI.
Nth degree Polynomial with two variables.
Namespace for the standard library.
TNT::Array2D< double > AMatrix
Affine Matrix.
#define _FILEINFO_
Macro for the filename and line number.
Generic least square fitting class.
void AddKnown(const std::vector< double > &input, double expected, double weight=1.0)
Invoke this method for each set of knowns.
double Coefficient(int i) const
Returns the ith coefficient.
Namespace for ISIS/Bullet specific routines.
int Solve(Isis::LeastSquares::SolveMethod method=SVD)
After all the data has been registered through AddKnown, invoke this method to solve the system of eq...