BRL-CAD
Loading...
Searching...
No Matches
Principle Component Analysis (PCA)
Collaboration diagram for Principle Component Analysis (PCA):

Functions

int bg_pca (point_t *c, vect_t *xaxis, vect_t *yaxis, vect_t *zaxis, size_t npnts, point_t *pnts)
 Perform a Principle Component Analysis on a set of points.
 

Detailed Description

Principle Component Analysis

Calculates an XYZ coordinate system such that it aligns with the largest variations in the supplied data. Intuitively, it "aligns" with the shape of the points.

To apply the coordinate system to the input points to relocate them to the aligned position in model space, you can construct matrices and apply them:

point_t center;
bg_pca(&center, &xaxis, &yaxis, &zaxis, pntcnt, pnts);
mat_t R, T, RT;
// Rotation
VMOVE(&R[0], xaxis);
VMOVE(&R[4], yaxis);
VMOVE(&R[8], zaxis);
// Translation
// Combine
// Apply
for (size_t i = 0; i < pntcnt; i++) {
MAT4X3PNT(p, RT, pnts[i]);
VMOVE(pnts[i], v);
}
Definition dvec.h:74
int bg_pca(point_t *c, vect_t *xaxis, vect_t *yaxis, vect_t *zaxis, size_t npnts, point_t *pnts)
Perform a Principle Component Analysis on a set of points.
void bn_mat_mul(mat_t o, const mat_t a, const mat_t b)
fastf_t vect_t[ELEMENTS_PER_VECT]
3-tuple vector
Definition vmath.h:349
#define MAT_IDN(m)
Set matrix to identity.
Definition vmath.h:767
fastf_t mat_t[ELEMENTS_PER_MAT]
4x4 matrix
Definition vmath.h:370
#define VMOVE(o, v)
Transfer 3D vector at ā€˜v’ to vector at ā€˜o’.
Definition vmath.h:865
#define MAT_DELTAS_VEC_NEG(_m, _v)
set translation values of 4x4 matrix from a reversed vector.
Definition vmath.h:609
fastf_t point_t[ELEMENTS_PER_POINT]
3-tuple point
Definition vmath.h:355
#define MAT4X3PNT(o, m, i)
Apply a 4x4 matrix to a 3-tuple which is an absolute Point in space. Output and input points should b...
Definition vmath.h:1685

Function Documentation

◆ bg_pca()

int bg_pca ( point_t c,
vect_t xaxis,
vect_t yaxis,
vect_t zaxis,
size_t  npnts,
point_t pnts 
)
extern

Perform a Principle Component Analysis on a set of points.

Outputs are a center point and XYZ vectors for the coordinate system.

Parameters
[out]cOrigin of aligned coordinate system
[out]xaxisVector of X axis of aligned coordinate system (unit length)
[out]yaxisVector of Y axis of aligned coordinate system (unit length)
[out]zaxisVector of Z axis of aligned coordinate system (unit length)
[in]npntsNumber of points in input pnts array
[in]pntsArray of points to analyze
Returns
BRLCAD_OK success
BRLCAD_ERROR if inputs are invalid or calculation fails