index

Varkon MBS Programmers manual

# pca - Function

## Description

Low level routine to create a 4x4 matrix by using a statistical method called Principal Component Analysis(PCA) and specifying a set of points (point cloud) stored in a one dimension array. The result is a 4x4 matrix, which might be used to create a coordinate system or transformation matrix.

For more details see "Mathematics for 3D Game Programming and Computer Graphics" Authored by Eric Lengyel - second edition, pages 217--221.

## Syntax

    status:=pca(npts,pts,tmat);

INT | status;
INT | npts;
VECTOR | pts(npts);
FLOAT | tmat(4,4);

## Principal parameters

npts | - Number of points
pts | - Array of points
tmat | - 4x4 transformation matrix

## Optional parameters

None.

## Return Value

0 | => | Operation is successful.
-1 | => | No. of input points is less than 4.
-2 | => | The input points are identical.
-3 | => | The input points are are on straight line.

## Comments

The created 4x4 matrix will be like the following matrix:

Xx | Xy | Xz | Ox
Yx | Yy | Yz | Oy
Zx | Zy | Zz | OZ
0 | 0 | 0 | 1

Since:

Xx, Yx, Zx | => | The unit length eigenvector components correspond to the largest eigenvalue.
Xy, Yy, Zy | => | The unit length eigenvector components correspond to the second largest eigen value.
Xz, Yz, Zz | => | The unit length eigenvector components correspond to the smallest eigen value.
Ox, Oy, Oz | => | The mean of the set of points represents the translation transformation.

The three eigen vectors are orthogonal to each other.

Be aware that in the last two cases of the return value when (status = -2 or -3), the created 4x4 transformation matrix not represents some characetristics of the given data like the planarity property. In other words in case of calculate a point on the fitted plane to the given data and its normal vector, the return value of the function should be equal to 0 (status= 0).

To visualize or use the 4x4 matrix that represents the coordinate system, use csys_usrdef(), in this case the fitted plane to the given data is XY - plane and the normal vector is the Z axis of the created coordinate system, see below.

## See also

csys_usrdef() and tform_usrdef

Varkon version 1.19C svn# 120