Software Engineering Home
Least Squares Fitting Two Sets of Coordinates : Code Sample

User code:

....


// Contruct a 163 x 3 Matrix from an array of float

Matrix m( arr1, 163, 3 );


// Contruct a vector of 163 x 3 floats from a second array

vector<float> v( arr2, arr2+163*3 );


// Set up typedefs to increase readablility of code 

typedef Matrix::iterator iterator;
typedef vector<float>::const_iterator const_iterator;
typedef LeastSquaresFit LSQ;


// Fit the coordinates in the Matrix to those in the vector

double RMSD = LSQ::Fit( m.begin(), m.end(), v.begin(), v.end() );


BTL code:



template <class ForwardIterator, class ConstForwardIterator> 
class LeastSquatesFit
{
public:
	

    // Least squares fit 1st set of coordinates to 2nd using
    // Kearsley's method

    static REAL
    Fit(ForwardIterator begin1, ForwardIterator end1,
        ConstForwardIterator begin2, ConstForwardIterator end2);
	   ...
};





Back Back