Graphics Reference
In-Depth Information
= c ij for a collection of n points P 1 , P 2 , ... , P n is given by
The covariance matrix C
n
P k , i
u i P k , j
u j ,
1
n
c ij =
k
=
1
or equivalently by
n
P k , i P k , j
1
n
c ij
=
u i u j .
k
=
1
The u i (and u j ) term is the mean of the i -th coordinate value of the points, given by
n
1
n
u i
=
P k , i .
k
=
1
Informally, to see how covariance works, consider the first covariance formula. When
two variables tend to deviate in the same direction from their respective means, the
product,
P k , i
u i P k , j
u j ,
will be positive more often than negative. If the variables tend to deviate in dif-
ferent directions, the product will be negative more often than positive. The sum
of these products identifies how the variables co-vary. When implemented using
single-precision floats, the former of the two covariance formulas tends to produce
results that are more accurate by retaining more bits of precision. Using double
precision, there is typically little or no difference in the results. The following code
implements the first formula:
void CovarianceMatrix(Matrix33 &cov, Point pt[], int numPts)
{
float oon = 1.0f / (float)numPts;
Point c = Point(0.0f, 0.0f, 0.0f);
float e00, e11, e22, e01, e02, e12;
// Compute the center of mass (centroid) of the points
for(inti=0;i<numPts; i++)
 
Search WWH ::




Custom Search