@@ -0,0 +1,2272 @@
+package org.biojava.nbio.structure.symmetry.geometry;%0A%0Aimport javax.vecmath.Point3d;%0Aimport javax.vecmath.Quat4d;%0A%0A/**%0A * Quaternions is a static Class that contains methods for calculating and using%0A * quaternions.%0A * %3Cp%3E%0A * A Quaternion is a four-dimensional vector used to describe a%0A * three-dimensional attitude representation (axis and angle of rotation).%0A * %0A * @author Aleix Lafita%0A * @since 5.0.0%0A *%0A */%0Apublic class Quaternions %7B%0A%0A%09/** Prevent instantiation */%0A%09private Quaternions() %7B%0A%09%7D%0A%0A%09/**%0A%09 * The orientation metric is obtained by comparing the quaternion%0A%09 * orientations of two superposed sets of points in 3D.%0A%09 * %3Cp%3E%0A%09 * First, the quaternion orientation of each set of points is calculated%0A%09 * using their principal axes. Then, the two quaternions are compared using%0A%09 * the formula: d(q1,q2) = arccos(%7Cq1*q2%7C)%0A%09 * %3Cp%3E%0A%09 * The formula is taken from: Huynh, D. Q. (2009). Metrics for 3D rotations:%0A%09 * comparison and analysis. Journal of Mathematical Imaging and Vision,%0A%09 * 35(2), 155%E2%80%93164. http://doi.org/10.1007/s10851-009-0161-2%0A%09 * %0A%09 * @return the quaternion orientation metric%0A%09 */%0A%09public static double orientationMetric(Point3d%5B%5D a, Point3d%5B%5D b) %7B%0A%0A%09%09Quat4d qa = orientation(a);%0A%09%09Quat4d qb = orientation(b);%0A%0A%09%09qa.mul(qb);%0A%0A%09%09double score;%0A%0A%09%09return 0.0;%0A%09%7D%0A%0A%09/**%0A%09 * The orientation represents the rotation of the principal axes with%0A%09 * respect to the axes of the coordinate system (unit vectors %5B1,0,0%5D,%0A%09 * %5B0,1,0%5D and %5B0,0,1%5D). The rotation can be expressed as a quaternion.%0A%09 * %0A%09 * @param points%0A%09 *            array of Point3d%0A%09 * @return the orientation as a quaternion%0A%09 */%0A%09public static Quat4d orientation(Point3d%5B%5D points) %7B%0A%0A%09%09MomentsOfInertia moi = new MomentsOfInertia();%0A%0A%09%09for (Point3d p : points)%0A%09%09%09moi.addPoint(p, 1.0);%0A%0A%09%09// Convert rotation matrix to quaternion%0A%09%09Quat4d quat = new Quat4d();%0A%09%09quat.set(moi.getOrientationMatrix());%0A%0A%09%09return quat;%0A%09%7D%0A%0A%09/**%0A%09 * Return the length of the quaternion (the norm, the magnitude). The length%0A%09 * of the quaternion is obtained by multiplying by its conjugate and taking%0A%09 * the square root of the sum of terms.%0A%09 * %0A%09 * @param q%0A%09 *            quaternion as Quat4d object%0A%09 * @return the length of the quaterion%0A%09 */%0A%09public static double length(Quat4d q) %7B%0A%09%09return 0.0;%0A%09%7D%0A%0A%7D%0A

Create new Quaternions Class with orientation metric