15#include <jama/jama_svd.h>
18#include "IException.h"
20#include "LeastSquares.h"
21#include "PolynomialBivariate.h"
63 for(
int i = 0 ; i < ident.dim2() ; i++) {
93 const double xp[],
const double yp[],
int n) {
101 for(
int i = 0; i < n; i++) {
102 vector<double> coord(2);
154 double angleRadians = angle * Isis::PI / 180.0;
155 rot[0][0] = cos(angleRadians);
156 rot[0][1] = -sin(angleRadians);
157 rot[1][0] = sin(angleRadians);
158 rot[1][1] = cos(angleRadians);
161 angleRadians = -angleRadians;
162 rot[0][0] = cos(angleRadians);
163 rot[0][1] = -sin(angleRadians);
164 rot[1][0] = sin(angleRadians);
165 rot[1][1] = cos(angleRadians);
176 scale[0][0] = scaleFactor;
177 scale[1][1] = scaleFactor;
222 vector <double> coef;
239 vector <double> coef;
252 if((am.dim1() != 3) && (am.dim2() != 3)) {
254 mess <<
"Affine matrices must be 3x3 - this one is " << am.dim1()
256 throw IException(IException::Programmer, mess.str(), _FILEINFO_);
276 JAMA::SVD<double> svd(a);
284 for(
int i = 0; i < invS.dim1(); i++) {
285 if(invS[i][i] == 0.0) {
286 string msg =
"Affine transform not invertible";
287 throw IException(IException::Unknown, msg, _FILEINFO_);
289 invS[i][i] = 1.0 / invS[i][i];
295 AMatrix transU(U.dim2(), U.dim1());
296 for(
int r = 0; r < U.dim1(); r++) {
297 for(
int c = 0; c < U.dim2(); c++) {
298 transU[c][r] = U[r][c];
303 AMatrix VinvS = TNT::matmult(V, invS);
304 return (TNT::matmult(VinvS, transU));
std::vector< double > Coefficients(int var)
Return the affine coeffients for the entered variable (1 or 2).
void ComputeInverse(double xp, double yp)
Compute (x,y) given (xp,yp).
double xp() const
Returns the computed x'.
double p_xp
x' value of the (x',y') coordinate
double y() const
Returns the computed y.
AMatrix p_matrix
Affine forward matrix.
AMatrix p_invmat
Affine inverse matrix.
void Translate(double tx, double ty)
Apply a translation to the current affine transform.
static AMatrix getIdentity()
Return an Affine identity matrix.
double yp() const
Returns the computed y'.
double p_yp
y' value of the (x',y') coordinate
TNT::Array2D< double > AMatrix
Affine Matrix.
void Scale(double scaleFactor)
Apply a scale to the current affine transform.
AMatrix invert(const AMatrix &a) const
Compute the inverse of a matrix.
double p_y
y value of the (x,y) coordinate
void Compute(double x, double y)
Compute (xp,yp) given (x,y).
~Affine()
Destroys the Affine object.
double p_x
x value of the (x,y) coordinate
Affine()
Constructs an Affine transform.
void Identity()
Set the forward and inverse affine transform to the identity.
void Solve(const double x[], const double y[], const double xp[], const double yp[], int n)
Given a set of coordinate pairs (n >= 3), compute the affine transform that best fits the points.
void checkDims(const AMatrix &am) const
Checks affine matrix to ensure it is a 3x3 standard form transform.
std::vector< double > InverseCoefficients(int var)
Return the inverse affine coeffients for the entered variable (1 or 2).
void Rotate(double rot)
Apply a translation to the current affine transform.
double x() const
Returns the computed x.
double Coefficient(int i) const
Returns the ith coefficient.
Generic least square fitting class.
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...
void AddKnown(const std::vector< double > &input, double expected, double weight=1.0)
Invoke this method for each set of knowns.
Nth degree Polynomial with two variables.
This is free and unencumbered software released into the public domain.
Namespace for the standard library.