First the two sets of points are translated so that their centroids are at the origin to give
and
, i.e., the matrices will have zero column means. Then the rotation of the translated
matrix which minimizes the sum of squared distances between corresponding points in the two sets is found. This is computed from the singular value decomposition of the matrix:
where
and
are orthogonal matrices and
is a diagonal matrix. The matrix of rotations,
, is computed as:
After rotation, a scaling or dilation factor,
, may be estimated by least squares. Thus, the final set of points that best match
is given by:
Before rotation, both sets of points may be normalized to have unit sums of squares or the
matrix may be normalized to have the same sum of squares as the
matrix. After rotation, the results may be translated to the original
centroid.
-
1:
– Nag_TransNorm
Input
-
On entry: indicates if translation/normalization is required.
- No translation or normalization.
- Translation to the origin.
- Translation to the origin and then to the centroid after rotation.
- Unit normalization.
- Translation and normalization.
- Translation and normalization to scale, then translation to the centroid after rotation.
Constraint:
, , , , or .
-
2:
– Nag_RotationScale
Input
-
On entry: indicates if least squares scaling is applied after rotation.
- Scaling is to be applied.
- No scaling is applied.
Constraint:
or .
-
3:
– Integer
Input
-
On entry: the number of points, .
Constraint:
.
-
4:
– Integer
Input
-
On entry: the number of dimensions, .
-
5:
– double
Input/Output
-
Note: the th element of the matrix is stored in .
On entry: the matrix to be rotated, .
On exit: if
,
x will be unchanged.
If
,
,
or
,
x will be translated to have zero column means.
If
or
,
x will be scaled to have unit sum of squares.
If
,
x will be scaled to have the same sum of squares as
y.
-
6:
– Integer
Input
-
On entry: the stride separating matrix column elements in the array
x.
Constraint:
.
-
7:
– double
Input/Output
-
Note: the th element of the matrix is stored in .
On entry: the target matrix, .
On exit: if
, then
y will be unchanged.
If
or
, then
y will be translated to have zero column means.
If
or
, then
y will be scaled to have unit sum of squares.
If
or
, then
y will be translated and then after rotation, translated back. The output
y should be the same as the input
y except for rounding errors.
-
8:
– Integer
Input
-
On entry: the stride separating matrix column elements in the arrays
y,
yhat.
Constraint:
.
-
9:
– double
Output
-
Note: the th element of the matrix is stored in .
On exit: the fitted matrix, .
-
10:
– double
Output
-
Note: the th element of the matrix is stored in .
On exit: the matrix of rotations,
, see
Section 9.
-
11:
– Integer
Input
-
On entry: the stride separating matrix column elements in the array
r.
Constraint:
.
-
12:
– double *
Output
-
On exit: if
the scaling factor,
; otherwise
alpha is not set.
-
On exit: the residual sum of squares.
-
14:
– double
Output
-
On exit: the residuals, , for .
-
15:
– NagError *
Input/Output
-
The NAG error argument (see
Section 7 in the Introduction to the NAG Library CL Interface).
The accuracy of the calculation of the rotation matrix largely depends upon the singular value decomposition. See the
F08 Chapter Introduction for further details.
Please consult the
X06 Chapter Introduction for information on how to control and interrogate the OpenMP environment used within this function. Please also consult the
Users' Note for your implementation for any additional implementation-specific information.
Note that if the matrix
is not of full rank, then the matrix of rotations,
, may not be unique even if there is a unique solution in terms of the rotated matrix,
. The matrix
may also include reflections as well as pure rotations, see
Krzanowski (1990).
Three points representing the vertices of a triangle in two dimensions are input. The points are translated and rotated to match the triangle given by (0,0),(1,0),(0,2) and scaling is applied after rotation. The target matrix and fitted matrix are printed along with additional information.