public void translate(double x, double y, double z) { Matrix4d matrix = this.matrixStack.peek(); Matrix4d translation = new Matrix4d(); translation.setIdentity(); translation.setTranslation(new Vector3d(x, y, z)); matrix.mul(translation); }
/** * Use the given GMatrix to transform the given points inplace. * * @param m4d * the matrix to use (e.g. the inverse matrix or the forward matrix. * @param srcPts * The array containing the source point coordinates. */ private void transform( Matrix4d m4d, List<Point3d> srcPts ) { for ( Point3d p : srcPts ) { m4d.transform( p ); } }
@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)); }
/** * Adds translational component to rotation matrix * @param rotTrans * @param rotation * @return */ private void combineWithTranslation(Matrix4d rotation) { rotation.setTranslation(centroid); rotation.mul(rotation, centroidInverse); }
/** * Tells whether this transformation is in identity. * @return */ public boolean isIdentity() { return transformation.epsilonEquals(new Matrix4d(1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1), 0.00000000001); }
/** * Returns true if the given CrystalTransform is equivalent to this one. * Two crystal transforms are equivalent if one is the inverse of the other, i.e. * their transformation matrices multiplication is equal to the identity. * @param other * @return */ public boolean isEquivalent(CrystalTransform other) { Matrix4d mul = new Matrix4d(); mul.mul(this.matTransform,other.matTransform); if (mul.epsilonEquals(IDENTITY, 0.0001)) { return true; } return false; }
Matrix4d mat = new Matrix4d(); mat.setIdentity(); Matrix4d transform = new Matrix4d(); transform.rotY(rot / 180 * Math.PI); mat.mul(transform); transform.setIdentity(); transform.setTranslation(new Vector3d(cube.getPosition())); mat.mul(transform); double rotZ = cube.getRotation()[2]; transform.rotZ(rotZ / 180 * Math.PI); mat.mul(transform); transform.rotY(rotY / 180 * Math.PI); mat.mul(transform); transform.rotX(rotX / 180 * Math.PI); mat.mul(transform);
Matrix4d transform = new Matrix4d(); transform.setIdentity(); continue; if (counts[t] > 0) { Matrix4d axis = new Matrix4d(axes.get(t).getOperator()); for(int i=0;i<counts[t];i++) transform.mul(axis); } else if (counts[t] < 0) { Matrix4d axis = new Matrix4d(axes.get(t).getOperator()); axis.invert(); for(int i=0;i<counts[t];i++) transform.mul(axis);
private Matrix4d reorientHelix(int index) { Matrix4d matrix = new Matrix4d(); matrix.setIdentity(); matrix.setRotation(new AxisAngle4d(1,0,0,Math.PI/2*(index+1))); matrix.mul(transformationMatrix); return matrix; }
public Matrix() { this.matrixStack = new Stack<>(); Matrix4d matrix = new Matrix4d(); matrix.setIdentity(); this.matrixStack.push(matrix); }
private static Matrix4d flipZ() { Matrix4d rot = new Matrix4d(); rot.m00 = -1; rot.m11 = -1; rot.m22 = 1; rot.m33 = 1; return rot; }
/** * * @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 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; }
public static Matrix4d getMatrixFromAlgebraic(String transfAlgebraic) { String[] parts = transfAlgebraic.toUpperCase().split(","); double[] xCoef = convertAlgebraicStrToCoefficients(parts[0].trim()); double[] yCoef = convertAlgebraicStrToCoefficients(parts[1].trim()); double[] zCoef = convertAlgebraicStrToCoefficients(parts[2].trim()); Matrix4d mat = new Matrix4d(); mat.setIdentity(); mat.setRotation(new Matrix3d(xCoef[0],xCoef[1],xCoef[2],yCoef[0],yCoef[1],yCoef[2],zCoef[0],zCoef[1],zCoef[2])); mat.setTranslation(new Vector3d(xCoef[3],yCoef[3],zCoef[3])); return mat; //return new Matrix4d(xCoef[0],xCoef[1],xCoef[2],xCoef[3], // yCoef[0],yCoef[1],yCoef[2],yCoef[3], // zCoef[0],zCoef[1],zCoef[2],zCoef[3], // 0,0,0,1); }
/** * Return the transformation that needs to be applied to a * repeat in order to superimpose onto repeat 0. * * @param repeat the repeat index * @return transformation matrix for the repeat */ public Matrix4d getRepeatTransform(int repeat){ Matrix4d transform = new Matrix4d(); transform.setIdentity(); int[] counts = getAxisCounts(repeat); for(int t = counts.length-1; t>=0; t--) { if( counts[t] == 0 ) continue; Matrix4d axis = new Matrix4d(axes.get(t).getOperator()); for(int i=0;i<counts[t];i++) { transform.mul(axis); } } return transform; }
Matrix4d mChainIInv = new Matrix4d(chainNcsOps.get(chainIName)); mChainIInv.invert(); Matrix4d mJNcs = new Matrix4d(chainNcsOps.get(chainJName)); Matrix4d j2iNcsOrigin = new Matrix4d(mChainIInv); j2iNcsOrigin.mul(mJCryst); j2iNcsOrigin.mul(mJNcs); Matrix4d i2jNcsOrigin = new Matrix4d(j2iNcsOrigin); i2jNcsOrigin.invert(); visitedNcsChainPairs.computeIfAbsent(matchChainIdsIJ, k-> new HashMap<>()).entrySet().stream(). map(r->r.getKey()). filter(r->r.epsilonEquals(j2iNcsOrigin,0.01)). findFirst(); visitedNcsChainPairs.computeIfAbsent(matchChainIdsJI, k-> new HashMap<>()).entrySet().stream(). map(r->r.getKey()). filter(r->r.epsilonEquals(i2jNcsOrigin,0.01)). findFirst(); matchMatrix = matchInverse.orElse(null);
@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)); }
Matrix4d currAxisOp = new Matrix4d(prior); currAxisOp.invert(); currAxisOp.mul(elemOp); currAxisOp.mul(prior); Axis currAxis = new Axis(currAxisOp,elem.getOrder(),elem.getSymmType(),level,firstRepeat); symmAxes.add(currAxis); Matrix4d newPrior = new Matrix4d(elemOp); newPrior.mul(prior); int childSize = getNumRepeats(level+1); getSymmetryAxes(symmAxes,newPrior,level+1,firstRepeat+childSize); for(int d=2;d<elem.getOrder();d++) { newPrior.mul(elemOp,newPrior); getSymmetryAxes(symmAxes,newPrior,level+1,firstRepeat+childSize*d);