BRL-CAD
Loading...
Searching...
No Matches
pca.h
Go to the documentation of this file.
1/* P C A . H
2 * BRL-CAD
3 *
4 * Copyright (c) 2004-2025 United States Government as represented by
5 * the U.S. Army Research Laboratory.
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public License
9 * version 2.1 as published by the Free Software Foundation.
10 *
11 * This library is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this file; see the file named COPYING for more
18 * information.
19 */
20
21/*----------------------------------------------------------------------*/
22/** @addtogroup bg_pca
23 *
24 * Principle Component Analysis
25 *
26 * Calculates an XYZ coordinate system such that it aligns with the largest
27 * variations in the supplied data. Intuitively, it "aligns" with the
28 * shape of the points.
29 *
30 * To apply the coordinate system to the input points to relocate them to
31 * the aligned position in model space, you can construct matrices and
32 * apply them:
33 *
34 * @code
35 * point_t center;
36 * vect_t xaxis, yaxis, zaxis;
37 * bg_pca(&center, &xaxis, &yaxis, &zaxis, pntcnt, pnts);
38 * mat_t R, T, RT;
39 * // Rotation
40 * MAT_IDN(R);
41 * VMOVE(&R[0], xaxis);
42 * VMOVE(&R[4], yaxis);
43 * VMOVE(&R[8], zaxis);
44 * // Translation
45 * MAT_IDN(T);
46 * MAT_DELTAS_VEC_NEG(T, center);
47 * // Combine
48 * bn_mat_mul(RT, R, T);
49 * // Apply
50 * point_t p;
51 * for (size_t i = 0; i < pntcnt; i++) {
52 * MAT4X3PNT(p, RT, pnts[i]);
53 * VMOVE(pnts[i], v);
54 * }
55 * @endcode
56 */
57/** @{ */
58/* @file pca.h */
59
60#ifndef BG_PCA_H
61#define BG_PCA_H
62
63#include "common.h"
64#include "vmath.h"
65#include "bg/defines.h"
66
67__BEGIN_DECLS
68
69
70/**
71 * @brief
72 * Perform a Principle Component Analysis on a set of points.
73 *
74 * Outputs are a center point and XYZ vectors for the coordinate system.
75 *
76 * @param[out] c Origin of aligned coordinate system
77 * @param[out] xaxis Vector of X axis of aligned coordinate system (unit length)
78 * @param[out] yaxis Vector of Y axis of aligned coordinate system (unit length)
79 * @param[out] zaxis Vector of Z axis of aligned coordinate system (unit length)
80 * @param[in] npnts Number of points in input pnts array
81 * @param[in] pnts Array of points to analyze
82 *
83 * @return BRLCAD_OK success
84 * @return BRLCAD_ERROR if inputs are invalid or calculation fails
85 *
86 */
87BG_EXPORT extern int bg_pca(point_t *c, vect_t *xaxis, vect_t *yaxis, vect_t *zaxis, size_t npnts, point_t *pnts);
88
89__END_DECLS
90
91#endif /* BG_PLANE_H */
92/** @} */
93/*
94 * Local Variables:
95 * mode: C
96 * tab-width: 8
97 * indent-tabs-mode: t
98 * c-file-style: "stroustrup"
99 * End:
100 * ex: shiftwidth=4 tabstop=8
101 */
Header file for the BRL-CAD common definitions.
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 int * c
Definition tig.h:139
fastf_t vect_t[ELEMENTS_PER_VECT]
3-tuple vector
Definition vmath.h:349
fastf_t point_t[ELEMENTS_PER_POINT]
3-tuple point
Definition vmath.h:355
fundamental vector, matrix, quaternion math macros