Skip to content

Commit

Permalink
Merge branch 'ellipsoid-factor' into testing
Browse files Browse the repository at this point in the history
Conflicts:
	src/org/bonej/Help.java
  • Loading branch information
mdoube committed Jan 23, 2015
2 parents 7af68c1 + ab37356 commit dd870a9
Show file tree
Hide file tree
Showing 9 changed files with 2,753 additions and 318 deletions.
1,641 changes: 1,641 additions & 0 deletions src/org/bonej/EllipsoidFactor.java

Large diffs are not rendered by default.

279 changes: 0 additions & 279 deletions src/org/doube/bonej/PlateRod.java

This file was deleted.

60 changes: 60 additions & 0 deletions src/org/doube/geometry/EigenCalculator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package org.doube.geometry;

import org.doube.jama.EigenvalueDecomposition;
import org.doube.jama.Matrix;

public class EigenCalculator {

/**
* Calculate the eigenvectors and eigenvalues of a set of points by the
* covariance method and eigendecomposition.
*
* @param coOrdinates
* n x 3 array
* @return EigenvalueDecomposition containing eigenvectors and eigenvalues
*
*/
public static EigenvalueDecomposition principalComponents(
double[][] coOrdinates) {
final int nPoints = coOrdinates.length;
double sumX = 0, sumY = 0, sumZ = 0;
//calculate the centroid of the points
for (int n = 0; n < nPoints; n++) {
sumX += coOrdinates[n][0];
sumY += coOrdinates[n][1];
sumZ += coOrdinates[n][2];
}
//centroid is the mean (x, y, z) position
final double centX = sumX / nPoints;
final double centY = sumY / nPoints;
final double centZ = sumZ / nPoints;

//construct the covariance matrix
double[][] C = new double[3][3];
double count = 0;
for (int n = 0; n < nPoints; n++) {
//translate so that centroid is at (0,0,0)
final double x = coOrdinates[n][0] - centX;
final double y = coOrdinates[n][1] - centY;
final double z = coOrdinates[n][2] - centZ;
C[0][0] += x * x;
C[1][1] += y * y;
C[2][2] += z * z;
final double xy = x * y;
final double xz = x * z;
final double yz = y * z;
C[0][1] += xy;
C[0][2] += xz;
C[1][0] += xy;
C[1][2] += yz;
C[2][0] += xz;
C[2][1] += yz;
count += 1;
}
double invCount = 1 / count;
Matrix covarianceMatrix = new Matrix(C).times(invCount);
EigenvalueDecomposition E = new EigenvalueDecomposition(
covarianceMatrix);
return E;
}
}
Loading

0 comments on commit dd870a9

Please sign in to comment.