public void rotate(Quat4f qaut) { Matrix4d matrix = this.matrixStack.peek(); Matrix4d rotation = new Matrix4d(); rotation.set(qaut); matrix.mul(rotation); }
private void initialize() { // translation to centered coordinate system centroid = new Vector3d(subunits.getCentroid()); // translation back to original coordinate system Vector3d reverse = new Vector3d(centroid); reverse.negate(); centroidInverse.set(reverse); // // On LINUX there seems to be a bug with vecmath, and element m33 is zero. Here we make sure it's 1. centroidInverse.setElement(3, 3, 1.0); }
/** * Superposition coords2 onto coords1 -- in other words, coords2 is rotated, * coords1 is held fixed */ private void calcTransformation() { // transformation.set(rotmat,new Vector3d(0,0,0), 1); transformation.set(rotmat); // long t2 = System.nanoTime(); // System.out.println("create transformation: " + (t2-t1)); // System.out.println("m3d -> m4d"); // System.out.println(transformation); // combine with x -> origin translation Matrix4d trans = new Matrix4d(); trans.setIdentity(); trans.setTranslation(new Vector3d(xtrans)); transformation.mul(transformation, trans); // System.out.println("setting xtrans"); // System.out.println(transformation); // combine with origin -> y translation ytrans.negate(); Matrix4d transInverse = new Matrix4d(); transInverse.setIdentity(); transInverse.setTranslation(new Vector3d(ytrans)); transformation.mul(transInverse, transformation); // System.out.println("setting ytrans"); // System.out.println(transformation); }
@Override public ResultSample doInverse3Test(final int count, final int maxCount, final long timeOutMS) { final Matrix4d mat = vecMatrixRandom(); final Matrix3d m1 = new Matrix3d( // mat.getElement(0, 0), mat.getElement(0, 1), mat.getElement(0, 2), // mat.getElement(1, 0), mat.getElement(1, 1), mat.getElement(1, 2), // mat.getElement(2, 0), mat.getElement(2, 1), mat.getElement(2, 2)); mat.setIdentity(); final long start = System.currentTimeMillis(); int loopCount = 0; while (System.currentTimeMillis() - start < timeOutMS && loopCount != maxCount) { ++loopCount; for (int i = 0; i < count; ++i) { m1.invert(); } } mat.set(m1); return populateResult(System.currentTimeMillis() - start, loopCount, toArray(mat)); }
public void rotate(Quat4d quat) { Matrix4d matrix = this.matrixStack.peek(); Matrix4d rotation = new Matrix4d(); rotation.set(quat); matrix.mul(rotation); }
private void initialize() { // translation to centered coordinate system centroid = new Vector3d(subunits.getCentroid()); // translation back to original coordinate system Vector3d reverse = new Vector3d(centroid); reverse.negate(); centroidInverse.set(reverse); // Make sure matrix element m33 is 1.0. An old version vecmath did not set this element. centroidInverse.setElement(3, 3, 1.0); List<Point3d> centers = subunits.getCenters(); int n = subunits.getSubunitCount(); originalCoords = new Point3d[n]; transformedCoords = new Point3d[n]; for (int i = 0; i < n; i++) { originalCoords[i] = centers.get(i); transformedCoords[i] = new Point3d(); } } }
private void calcZDirection() { calcBoundaries(); // if the longer part of the structure faces towards the back (-z direction), // rotate around y-axis so the longer part faces the viewer (+z direction) if (Math.abs(minBoundary.z) > Math.abs(maxBoundary.z)) { Matrix4d rot = flipY(); rot.mul(transformationMatrix); transformationMatrix.set(rot); } }
private static Vector3d[] getPolygonVertices(Vector3d axis, Vector3d referenceAxis, Point3d center, int n, double radius) { Vector3d ref = new Vector3d(referenceAxis); ref.scale(radius); AxisAngle4d axisAngle = new AxisAngle4d(axis, 0); Vector3d[] vectors = new Vector3d[n]; Matrix4d m = new Matrix4d(); for (int i = 0; i < n; i++) { axisAngle.angle = i * 2 * Math.PI/n; vectors[i] = new Vector3d(ref); m.set(axisAngle); // make sure matrix element m33 is 1.0. It's 0 on Linux. m.setElement(3, 3, 1.0); m.transform(vectors[i]); vectors[i].add(center); } return vectors; }
private void calcZDirection() { calcBoundaries(); // if the longer part of the structure faces towards the back (-z direction), // rotate around y-axis so the longer part faces the viewer (+z direction) if (Math.abs(minBoundary.z) > Math.abs(maxBoundary.z)) { Matrix4d rot = flipY(); rot.mul(transformationMatrix); transformationMatrix.set(rot); } }
private void initialize() { // translation to centered coordinate system centroid = new Vector3d(subunits.getCentroid()); // translation back to original coordinate system Vector3d reverse = new Vector3d(centroid); reverse.negate(); centroidInverse.set(reverse); // Make sure matrix element m33 is 1.0. An old version vecmath did not set this element. centroidInverse.setElement(3, 3, 1.0); List<Point3d> centers = subunits.getCenters(); int n = subunits.getSubunitCount(); originalCoords = new Point3d[n]; transformedCoords = new Point3d[n]; for (int i = 0; i < n; i++) { originalCoords[i] = centers.get(i); transformedCoords[i] = new Point3d(); } setupDistanceBox(); } }
/** * The QCP method can be used as a two-step calculation: first compute the * RMSD (fast) and then compute the superposition. * * This method assumes that the RMSD of two arrays of points has been * already calculated using {@link #getRmsd(Point3d[], Point3d[])} method * and calculates the transformation of the same two point arrays. * * @param fixed * @param moved * @return transformation matrix as a Matrix4d to superpose moved onto fixed * point arrays */ public Matrix4d superposeAfterRmsd() { if (!rmsdCalculated) { throw new IllegalStateException("The RMSD was not yet calculated. Use the superpose() method instead."); } getRotationMatrix(); if (!centered) { calcTransformation(); } else { transformation.set(rotmat); } return transformation; }
@Override public Matrix4d superpose(Point3d[] fixed, Point3d[] moved) { set(moved, fixed); getRotationMatrix(); if (!centered) { calcTransformation(); } else { transformation.set(rotmat); } return transformation; }
@Override public ResultSample doInverseTest(final int count, final int maxCount, final long timeOutMS) { final Matrix4d m1 = new Matrix4d(); final double near = 1.0, far = 1000.0, fovy = 90.0, aspect = 0.5; final double height = near * MathUtils.tan(fovy * 0.5 * MathUtils.DEG_TO_RAD); final double width = height * aspect; final double x = near / width; final double y = near / height; final double a = 0; final double b = 0; final double c = -(far + near) / (far - near); final double d = -(2.0 * far * near) / (far - near); m1.set(new double[] { x, 0.0, 0.0, 0.0, 0.0, y, 0.0, 0.0, a, b, c, -1.0, 0.0, 0.0, d, 0.0 }); final long start = System.currentTimeMillis(); int loopCount = 0; while (System.currentTimeMillis() - start < timeOutMS && loopCount != maxCount) { ++loopCount; for (int i = 0; i < count; ++i) { m1.invert(); } } return populateResult(System.currentTimeMillis() - start, loopCount, toArray(m1)); }
/** * Weighted superposition. * * @param fixed * @param moved * @param weight * array of weigths for each equivalent point position * @return */ public Matrix4d weightedSuperpose(Point3d[] fixed, Point3d[] moved, double[] weight) { set(moved, fixed, weight); getRotationMatrix(); if (!centered) { calcTransformation(); } else { transformation.set(rotmat); } return transformation; }
@Override public ResultSample doRotateTest1(final int count, final int maxCount, final long timeOutMS) { final Matrix4d m1 = vecMatrixRandom(); final Matrix4d m2 = new Matrix4d(); final Vector3d vec = new Vector3d(1.0, 2.0, 3.0); vec.normalize(); final AxisAngle4d rot = new AxisAngle4d(vec, MathUtils.HALF_PI); final long start = System.currentTimeMillis(); int loopCount = 0; while (System.currentTimeMillis() - start < timeOutMS && loopCount != maxCount) { ++loopCount; for (int i = 0; i < count; ++i) { // XXX: This is to approximate having a rotation and applying it to a matrix. // Don't optimize this by moving m2.set(...) out of loop or it is just a multiply test, and isn't // testing the same thing as everyone else. m2.set(rot); m1.mul(m2); } } return populateResult(System.currentTimeMillis() - start, loopCount, toArray(m1)); }
/** * * @param ops Set of operations in crystal coordinates * @param reference Reference point, which should be in the unit cell after * each operation (also in crystal coordinates) * @return A set of crystal operators with equivalent rotation to the * inputs, but with translation such that the reference point would fall * within the unit cell */ public Matrix4d[] transfToOriginCellCrystal(Matrix4d[] ops, Tuple3d reference) { Matrix4d[] transformed = new Matrix4d[ops.length]; for(int j=0;j<ops.length;j++) { Matrix4d op = ops[j]; // transform the reference point Point3d xXtal = new Point3d(reference); op.transform(xXtal); // Calculate unit cell of transformed reference int x = (int)Math.floor(xXtal.x); int y = (int)Math.floor(xXtal.y); int z = (int)Math.floor(xXtal.z); Matrix4d translation = new Matrix4d(); translation.set(new Vector3d(-x,-y,-z)); // Compose op with an additional translation operator translation.mul(op); Point3d ref2 = new Point3d(reference); translation.transform(ref2); transformed[j] = translation; } return transformed; }
private Matrix4d vecMatrixRandom() { final Matrix4d mat = new Matrix4d(); final Vector3d axis = new Vector3d(MathUtils.nextRandomDouble(), MathUtils.nextRandomDouble(), MathUtils.nextRandomDouble()); axis.normalize(); mat.set(new AxisAngle4d(axis, MathUtils.nextRandomDouble())); final double x = MathUtils.nextRandomDouble(); final double y = MathUtils.nextRandomDouble(); final double z = MathUtils.nextRandomDouble(); translate(mat, x, y, z); return mat; }
Matrix4d transformation = new Matrix4d(); transformation.set(quat); axisAngle.set(quat);