javax.vecmath.Matrix4d Java Examples

The following examples show how to use javax.vecmath.Matrix4d. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AFPTwister.java    From biojava with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Return the rmsd of the CAs between the input pro and this protein, at
 * given positions. quite similar to transPdb but while that one transforms
 * the whole ca2, this one only works on the res1 and res2 positions.
 *
 * Modifies the coordinates in the second set of Atoms (pro).
 *
 * @return rmsd of CAs
 */
private static double calCaRmsd(Atom[] ca1, Atom[] pro, int resn,
		int[] res1, int[] res2) throws StructureException {

	Atom[] cod1 = getAtoms(ca1, res1, resn, false);
	Atom[] cod2 = getAtoms(pro, res2, resn, false);

	if (cod1.length == 0 || cod2.length == 0) {
		logger.info("length of atoms  == 0!");
		return 99;
	}

	Matrix4d transform = SuperPositions.superpose(Calc.atomsToPoints(cod1),
			Calc.atomsToPoints(cod2));

	for (Atom a : cod2)
		Calc.transform(a.getGroup(), transform);

	return Calc.rmsd(cod1, cod2);
}
 
Example #2
Source File: TestNcsOpsParsing.java    From biojava with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * A structure (viral capsid) with struct_ncs_ops
 * @throws IOException
 * @throws StructureException
 */
@Test
public void test1auy() throws IOException, StructureException {

	AtomCache cache = new AtomCache();
	StructureIO.setAtomCache(cache);

	Structure s = StructureIO.getStructure("1auy");

	Matrix4d[] ops = s.getPDBHeader().getCrystallographicInfo().getNcsOperators();

	assertNotNull(ops);

	// the given operator must not be in our list, only the "generate" operators
	assertEquals(14, ops.length);

	for (Matrix4d op:ops) {
		assertEquals(0, op.m30, 0.000001);
		assertEquals(0, op.m31, 0.000001);
		assertEquals(0, op.m32, 0.000001);
		assertEquals(1, op.m33, 0.000001);
	}

}
 
Example #3
Source File: TestMmtfUtils.java    From biojava with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Test to check the conversion of BioassemblyInfo to a primitive map.
 */
@Test
public void testMakePrimitiveBioasembly() {
	double[] testData = new double[] {0.0, 0.1, 0.2, 0.3,
			1.0, 1.1, 1.2, 1.3,
			2.0, 2.1, 2.2, 2.3,
			3.0, 3.1, 3.2, 3.3};
	BioAssemblyInfo bioAssemblyInfo = new BioAssemblyInfo();
	List<BiologicalAssemblyTransformation> transforms = new ArrayList<>();
	BiologicalAssemblyTransformation biologicalAssemblyTransformation = new BiologicalAssemblyTransformation();
	biologicalAssemblyTransformation.setChainId("C");
	biologicalAssemblyTransformation.setTransformationMatrix(new Matrix4d(testData));
	transforms.add(biologicalAssemblyTransformation);
	bioAssemblyInfo.setTransforms(transforms);
	// Map the chain to the second index
	Map<String, Integer> chainIdToIndexMap = new HashMap<>();
	chainIdToIndexMap.put("C", 2);
	// Now do the conversion and test they are the same
	Map<double[], int[]> transMap = MmtfUtils.getTransformMap(bioAssemblyInfo, chainIdToIndexMap);
	assertArrayEquals(testData, (double[]) transMap.keySet().toArray()[0], 0.0);
	assertArrayEquals(new int[] {2} , (int[]) transMap.values().toArray()[0]);
}
 
Example #4
Source File: DHLink.java    From Robot-Overlord-App with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Set up the pose based on D-H parameters, then update the worldPose.
 * Equivalent to T(n) = TransZ(d) * RotZ(theta) * TransX(r) * RotX(alpha)
 */
public void refreshPoseMatrix() {
	double t=theta.get();
	double a=alpha.get();
	assert(!Double.isNaN(t));
	assert(!Double.isNaN(a));
	assert(!Double.isNaN(r.get()));
	assert(!Double.isNaN(d.get()));
	double ct = Math.cos(Math.toRadians(t));
	double ca = Math.cos(Math.toRadians(a));
	double st = Math.sin(Math.toRadians(t));
	double sa = Math.sin(Math.toRadians(a));
	Matrix4d m = new Matrix4d();
	
	m.m00 = ct;		m.m01 = -st*ca;		m.m02 = st*sa;		m.m03 = r.get()*ct;
	m.m10 = st;		m.m11 = ct*ca;		m.m12 = -ct*sa;		m.m13 = r.get()*st;
	m.m20 = 0;		m.m21 = sa;			m.m22 = ca;			m.m23 = d.get();
	m.m30 = 0;		m.m31 = 0;			m.m32 = 0;			m.m33 = 1;
	
	//Log.message(letter.get() + "="+m);
	setPose(m);
}
 
Example #5
Source File: MatrixHelper.java    From Robot-Overlord-App with GNU General Public License v2.0 6 votes vote down vote up
/**
 * See drawMatrix(gl2,p,u,v,w,1)
 * @param gl2
 * @param m
 * @param scale
 */
public static void drawMatrix(GL2 gl2,Matrix4d m,double scale) {
	boolean depthWasOn = gl2.glIsEnabled(GL2.GL_DEPTH_TEST);
	gl2.glDisable(GL2.GL_DEPTH_TEST);
	boolean lightWasOn = gl2.glIsEnabled(GL2.GL_LIGHTING);
	gl2.glDisable(GL2.GL_LIGHTING);
	
	gl2.glPushMatrix();
		gl2.glTranslated(m.m03,m.m13,m.m23);
		gl2.glScaled(scale, scale, scale);
		
		gl2.glBegin(GL2.GL_LINES);
		gl2.glColor3f(1,0,0);		gl2.glVertex3f(0,0,0);		gl2.glVertex3d(m.m00,m.m10,m.m20);  // 1,0,0 = red
		gl2.glColor3f(0,1,0);		gl2.glVertex3f(0,0,0);		gl2.glVertex3d(m.m01,m.m11,m.m21);  // 0,1,0 = green 
		gl2.glColor3f(0,0,1);		gl2.glVertex3f(0,0,0);		gl2.glVertex3d(m.m02,m.m12,m.m22);  // 0,0,1 = blue
		gl2.glEnd();

	gl2.glPopMatrix();
	if(lightWasOn) gl2.glEnable(GL2.GL_LIGHTING);
	if(depthWasOn) gl2.glEnable(GL2.GL_DEPTH_TEST);
}
 
Example #6
Source File: SpaceGroup.java    From biojava with GNU Lesser General Public License v2.1 6 votes vote down vote up
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);
}
 
Example #7
Source File: C2RotationSolver.java    From biojava with GNU Lesser General Public License v2.1 5 votes vote down vote up
private Rotation createSymmetryOperation(List<Integer> permutation, Matrix4d transformation, AxisAngle4d axisAngle, int fold, QuatSymmetryScores scores) {
	Rotation s = new Rotation();
	s.setPermutation(new ArrayList<Integer>(permutation));
	s.setTransformation(new Matrix4d(transformation));
	s.setAxisAngle(new AxisAngle4d(axisAngle));
	s.setFold(fold);
	s.setScores(scores);
	return s;
}
 
Example #8
Source File: MultipleAlignmentXMLConverter.java    From biojava with GNU Lesser General Public License v2.1 5 votes vote down vote up
public synchronized static void printXMLmatrix4d(PrettyXMLWriter xml,
		Matrix4d transform) throws IOException {

	if (transform == null) return;
	xml.openTag("Matrix4d");

	for (int x=0;x<4;x++){
		for (int y=0;y<4;y++){
			String key = "mat"+(x+1)+(y+1);
			String value = transform.getElement(x,y)+"";
			xml.attribute(key,value);
		}
	}
	xml.closeTag("Matrix4d");
}
 
Example #9
Source File: MmtfUtils.java    From biojava with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Convert a bioassembly information into a map of transform, chainindices it relates to.
 * @param bioassemblyInfo  the bioassembly info object for this structure
 * @param chainIdToIndexMap the map of chain ids to the index that chain corresponds to.
 * @return the bioassembly information (as primitive types).
 */
public static Map<double[], int[]> getTransformMap(BioAssemblyInfo bioassemblyInfo, Map<String, Integer> chainIdToIndexMap) {
    Map<Matrix4d, List<Integer>> matMap = new LinkedHashMap<>();
	List<BiologicalAssemblyTransformation> transforms = bioassemblyInfo.getTransforms();
	for (BiologicalAssemblyTransformation transformation : transforms) {
		Matrix4d transMatrix = transformation.getTransformationMatrix();
		String transChainId = transformation.getChainId();
		if (!chainIdToIndexMap.containsKey(transChainId)){
			continue;
		}
		int chainIndex = chainIdToIndexMap.get(transformation.getChainId());
		if(matMap.containsKey(transMatrix)){
			matMap.get(transMatrix).add(chainIndex);
		}
		else{
			List<Integer> chainIdList = new ArrayList<>();
			chainIdList.add(chainIndex);
			matMap.put(transMatrix, chainIdList);
		}
	}

    Map<double[], int[]> outMap = new LinkedHashMap<>();
	for (Entry<Matrix4d, List<Integer>> entry : matMap.entrySet()) {
		outMap.put(convertToDoubleArray(entry.getKey()), CodecUtils.convertToIntArray(entry.getValue()));
	}
	return outMap;
}
 
Example #10
Source File: BiologicalAssemblyBuilder.java    From biojava with GNU Lesser General Public License v2.1 5 votes vote down vote up
private ArrayList<BiologicalAssemblyTransformation> getBioUnitTransformationsListUnaryOperators(String assemblyId, List<PdbxStructAssemblyGen> psags) {
	ArrayList<BiologicalAssemblyTransformation> transformations = new ArrayList<BiologicalAssemblyTransformation>();


	for ( PdbxStructAssemblyGen psag : psags){
		if ( psag.getAssembly_id().equals(assemblyId)) {

			operatorResolver.parseOperatorExpressionString(psag.getOper_expression());
			List<String> operators = operatorResolver.getUnaryOperators();

			List<String>asymIds= Arrays.asList(psag.getAsym_id_list().split(","));

			// apply unary operators to the specified chains
			for (String chainId : asymIds) {
				for (String operator : operators) {
					Matrix4d original = allTransformations.get(operator);
					if (original == null) {
						logger.warn("Could not find matrix operator for operator id {}. Assembly id {} will not contain the operator.", operator, assemblyId);
						continue;
					}
					BiologicalAssemblyTransformation transform = new BiologicalAssemblyTransformation();
					transform.setChainId(chainId);
					transform.setId(operator);
					transform.setTransformationMatrix(original);
					transformations.add(transform);
				}
			}
		}
	}

	return transformations;
}
 
Example #11
Source File: Matrix4dEntity.java    From Robot-Overlord-App with GNU General Public License v2.0 5 votes vote down vote up
public void set(Matrix4d m) {
	super.set(m);
	
	Vector3d trans = MatrixHelper.getPosition(t);
	pos.set(trans);
	Vector3d r = MatrixHelper.matrixToEuler(t);
	rot.set(Math.toDegrees(r.x),
			Math.toDegrees(r.y),
			Math.toDegrees(r.z));
}
 
Example #12
Source File: SpaceGroup.java    From biojava with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Gets all transformations except for the identity in crystal axes basis.
 * @return
 */
public List<Matrix4d> getTransformations() {
	List<Matrix4d> transfs = new ArrayList<Matrix4d>();
	for (int i=1;i<this.transformations.size();i++){
		transfs.add(transformations.get(i));
	}
	return transfs;
}
 
Example #13
Source File: SymmetryAxes.java    From biojava with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Return the operator for all elementary axes of symmetry of the structure, that is,
 * the axes stored in the List as unique and from which all the symmetry
 * axes are constructed.
 *
 * @return axes elementary axes of symmetry.
 */
public List<Matrix4d> getElementaryAxes(){
	List<Matrix4d> ops = new ArrayList<Matrix4d>(getNumLevels());
	for(Axis axis : axes) {
		ops.add(axis.getOperator());
	}
	return ops;
}
 
Example #14
Source File: CrystalTransform.java    From biojava with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Copy constructor
 * @param transform
 */
public CrystalTransform(CrystalTransform transform) {
	this.sg = transform.sg;
	this.transformId = transform.transformId;
	this.matTransform = new Matrix4d(transform.matTransform);
	this.crystalTranslation = new Point3i(transform.crystalTranslation);
}
 
Example #15
Source File: SuperPositionQCP.java    From biojava with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * 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);
}
 
Example #16
Source File: BiologicalAssemblyBuilder.java    From biojava with GNU Lesser General Public License v2.1 5 votes vote down vote up
private ArrayList<BiologicalAssemblyTransformation> getBioUnitTransformationsListBinaryOperators(String assemblyId, List<PdbxStructAssemblyGen> psags) {

		ArrayList<BiologicalAssemblyTransformation> transformations = new ArrayList<>();

		List<OrderedPair<String>> operators = operatorResolver.getBinaryOperators();


		for ( PdbxStructAssemblyGen psag : psags){
			if ( psag.getAssembly_id().equals(assemblyId)) {

				List<String>asymIds= Arrays.asList(psag.getAsym_id_list().split(","));

				operatorResolver.parseOperatorExpressionString(psag.getOper_expression());

				// apply binary operators to the specified chains
				// Example 1M4X: generates all products of transformation matrices (1-60)(61-88)
				for (String chainId : asymIds) {

					for (OrderedPair<String> operator : operators) {
						Matrix4d original1 = allTransformations.get(operator.getElement1());
						Matrix4d original2 = allTransformations.get(operator.getElement2());
						if (original1 == null || original2 == null) {
							logger.warn("Could not find matrix operator for operator id {} or {}. Assembly id {} will not contain the composed operator.", operator.getElement1(), operator.getElement2(), assemblyId);
							continue;
						}
						Matrix4d composed = new Matrix4d(original1);
						composed.mul(original2);
						BiologicalAssemblyTransformation transform = new BiologicalAssemblyTransformation();
						transform.setChainId(chainId);
						transform.setId(operator.getElement1() + COMPOSED_OPERATOR_SEPARATOR + operator.getElement2());
						transform.setTransformationMatrix(composed);
						transformations.add(transform);
					}
				}
			}

		}

		return transformations;
	}
 
Example #17
Source File: TestMultipleAlignmentScorer.java    From biojava with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Generates a simple MultipleAlignment: 3 structures with the
 * same Atoms but incorreclty aligned with gaps.
 *
 * @return MultipleAlignment gapped MSTA
 * @throws StructureException
 */
private MultipleAlignment gappedMSTA() throws StructureException{

	//Generate three identical Atom arrays
	List<Atom[]> atomArrays = new ArrayList<Atom[]>(30);
	for (int i=0; i<3; i++) atomArrays.add(makeDummyCA(30));

	//Generate alignment with nulls and some missalignments
	List<List<Integer>> alnRes = new ArrayList<List<Integer>>(3);
	List<Integer> chain1 = Arrays.asList(
			1, 2, 	 3, 5, 8, 10, 12, 	 15, 17,  19, 22, null, 24, 27);
	List<Integer> chain2 = Arrays.asList(
			1, null, 3, 6, 9, 11, 12,   15, null, 18, 22, 24,   26, 28);
	List<Integer> chain3 = Arrays.asList(
			1, 2,    4, 7, 9, 10, null, 15, null, 17, 22, 24,   26, 28);

	alnRes.add(chain1);
	alnRes.add(chain2);
	alnRes.add(chain3);

	//MultipleAlignment generation
	MultipleAlignment msa = new MultipleAlignmentImpl();
	msa.getEnsemble().setAtomArrays(atomArrays);
	BlockSet bs = new BlockSetImpl(msa);
	Block b = new BlockImpl(bs);
	b.setAlignRes(alnRes);

	//We want the identity transfromations to mantain the missalignments
	Matrix4d ident = new Matrix4d();
	ident.setIdentity();
	bs.setTransformations(Arrays.asList(ident,ident,ident));

	return msa;
}
 
Example #18
Source File: RotationAxis.java    From biojava with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Create a rotation axis from a Matrix4d containing a rotational
 * component and a translational component.
 *
 * @param transform
 */
public RotationAxis(Matrix4d transform) {

	Matrix rot = Matrices.getRotationJAMA(transform);
	Atom transl = Calc.getTranslationVector(transform);
	init(rot,transl);
}
 
Example #19
Source File: FaceBakery.java    From The-5zig-Mod with MIT License 5 votes vote down vote up
private void a(Vector3f var, Vector3f var1, Matrix4d var2, Vector3f var3) {
	var.sub(var1);
	var2.transform(var);
	var.x *= var3.x;
	var.y *= var3.y;
	var.z *= var3.z;
	var.add(var1);
}
 
Example #20
Source File: Sixi2Live.java    From Robot-Overlord-App with GNU General Public License v2.0 5 votes vote down vote up
public void renderCartesianForce(GL2 gl2) {
	double len = Math.sqrt(
		cartesianForceDetected[0]*cartesianForceDetected[0]+
		cartesianForceDetected[1]*cartesianForceDetected[1]+
		cartesianForceDetected[2]*cartesianForceDetected[2]);
	if(len<1) return;
	//System.out.println(len);

	int previousState = OpenGLHelper.drawAtopEverythingStart(gl2);
	boolean lightWasOn = OpenGLHelper.disableLightingStart(gl2);
	gl2.glLineWidth(4);
	
	double scale=1;

	gl2.glPushMatrix();
		Matrix4d m4 = endEffector.getPoseWorld();
		gl2.glTranslated(m4.m03, m4.m13, m4.m23);

		gl2.glBegin(GL2.GL_LINES);
		gl2.glColor3d(0, 0.6, 1);
		gl2.glVertex3d(0,0,0);
		gl2.glVertex3d(
				cartesianForceDetected[0]*scale,
				cartesianForceDetected[1]*scale,
				cartesianForceDetected[2]*scale);
		
		gl2.glColor3d(1.0, 0.5, 0.5);	PrimitiveSolids.drawCircleYZ(gl2, cartesianForceDetected[3]*scale, 20);
		gl2.glColor3d(0.5, 1.0, 0.5);	PrimitiveSolids.drawCircleXZ(gl2, cartesianForceDetected[4]*scale, 20);
		gl2.glColor3d(0.5, 0.5, 1.0);	PrimitiveSolids.drawCircleXY(gl2, cartesianForceDetected[5]*scale, 20);
	
	gl2.glPopMatrix();

	gl2.glLineWidth(1);
	OpenGLHelper.disableLightingEnd(gl2, lightWasOn);
	OpenGLHelper.drawAtopEverythingEnd(gl2, previousState);
}
 
Example #21
Source File: C2RotationSolver.java    From biojava with GNU Lesser General Public License v2.1 5 votes vote down vote up
private void addEOperation() {
	List<Integer> permutation = Arrays.asList(0,1);
	Matrix4d transformation = new Matrix4d();
	transformation.setIdentity();
	combineWithTranslation(transformation);
	AxisAngle4d axisAngle = new AxisAngle4d();
	QuatSymmetryScores scores = new QuatSymmetryScores();
	int fold = 1; // ??
	Rotation rotation = createSymmetryOperation(permutation, transformation, axisAngle, fold, scores);
	rotations.addRotation(rotation);
}
 
Example #22
Source File: SpaceGroup.java    From biojava with GNU Lesser General Public License v2.1 5 votes vote down vote up
public SpaceGroup(int id, int multiplicity, int primitiveMultiplicity, String shortSymbol, String altShortSymbol, BravaisLattice bravLattice) {
	this.id = id;
	this.multiplicity = multiplicity;
	this.primitiveMultiplicity = primitiveMultiplicity;
	this.shortSymbol = shortSymbol;
	this.altShortSymbol = altShortSymbol;
	transformations = new ArrayList<Matrix4d>(multiplicity);
	transfAlgebraic = new ArrayList<String>(multiplicity);
	cellTranslations = new Vector3d[multiplicity/primitiveMultiplicity];
	this.bravLattice = bravLattice;
}
 
Example #23
Source File: PoseEntity.java    From Robot-Overlord-App with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Set the pose and poseWorld of this item
 * @param m
 */
public void setPoseWorld(Matrix4d m) {
	if(parent instanceof PoseEntity) {
		PoseEntity pep = (PoseEntity)parent;
		Matrix4d newPose = new Matrix4d(pep.poseWorld);
		newPose.invert();
		newPose.mul(m);
		setPose(newPose);
	} else {
		setPose(new Matrix4d(m));
	}
}
 
Example #24
Source File: DHIKSolver_Cartesian.java    From Robot-Overlord-App with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Starting from a known local origin and a known local hand position, calculate the travel for the given pose.
 * @param robot The DHRobot description. 
 * @param targetMatrix the pose that robot is attempting to reach in this solution.
 * @param keyframe store the computed solution in keyframe.
 */
@Override
public SolutionType solve(DHRobotEntity robot,Matrix4d targetMatrix,DHKeyframe keyframe) {
	Matrix4d targetPoseAdj = new Matrix4d(targetMatrix);
	
	if(robot.dhTool!=null) {
		// there is a transform between the wrist and the tool tip.
		// use the inverse to calculate the wrist Z axis and wrist position.
		robot.dhTool.refreshPoseMatrix();
		Matrix4d inverseToolPose = new Matrix4d(robot.dhTool.getPose());
		inverseToolPose.invert();
		targetPoseAdj.mul(inverseToolPose);
	}
	
	Matrix4d m4 = new Matrix4d(targetPoseAdj);

	keyframe.fkValues[0] = m4.m23;
	keyframe.fkValues[1] = m4.m03;
	keyframe.fkValues[2] = m4.m13;
 
	
	if(true) {
		Log.message("solution={"+StringHelper.formatDouble(keyframe.fkValues[0])+","+
				StringHelper.formatDouble(keyframe.fkValues[1])+","+
				StringHelper.formatDouble(keyframe.fkValues[2])+"}");
	}
	return SolutionType.ONE_SOLUTION;
}
 
Example #25
Source File: MmtfUtils.java    From biojava with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Get a list of length N*16 of a list of Matrix4d*N.
 * @param ncsOperators the {@link Matrix4d} list
 * @return the list of length N*16 of the list of matrices
 */
public static double[][] getNcsAsArray(Matrix4d[] ncsOperators) {
	if(ncsOperators==null){
		return new double[0][0];
	}
	double[][] outList = new double[ncsOperators.length][16];
	for(int i=0; i<ncsOperators.length;i++){
		outList[i] = convertToDoubleArray(ncsOperators[i]);
	}
	return outList;
}
 
Example #26
Source File: DHLink.java    From Robot-Overlord-App with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void setPoseWorld(Matrix4d newPose) {
	Matrix4d newRelativePose;
	if(parent instanceof PoseEntity) {
		PoseEntity pe = (PoseEntity)parent;
		newRelativePose=pe.getPoseWorld();
		newRelativePose.invert();
		newRelativePose.mul(newPose);
	} else {
		newRelativePose=newPose;
	}
	
	setPose(newRelativePose);
}
 
Example #27
Source File: DHLink.java    From Robot-Overlord-App with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Ask this entity "can you move to newPose?"
 * @param newWorldPose the desired world pose of the link
 * @return true if it can.
 */
@Override
public boolean canYouMoveTo(Matrix4d newWorldPose) {
	if( parent instanceof DHLink || parent instanceof DHRobotEntity ) {
		if( !this.getLetter().isEmpty() ) {
			Matrix4d oldPose=poseWorld;
			// we have newPose ...but is it something this DHLink could do?
			// For D-H links, the convention is that rotations are always around the Z axis.  the Z axis of each matrix should match.
			// TODO Today this is the only case I care about. make it better later.

			// difference in position
			double dx =Math.abs(newWorldPose.m03-oldPose.m03);
			double dy =Math.abs(newWorldPose.m13-oldPose.m13);
			double dz =Math.abs(newWorldPose.m23-oldPose.m23);
			if(dx+dy+dz>1e-6) return false;

			// difference in z axis
			dx =Math.abs(newWorldPose.m02-oldPose.m02);
			dy =Math.abs(newWorldPose.m12-oldPose.m12);
			dz =Math.abs(newWorldPose.m22-oldPose.m22);
			if(dx+dy+dz>1e-6) return false;
			// we made it here, move is legal!
			return true;
		}
	}
	// else default case
	return super.canYouMoveTo(newWorldPose);
}
 
Example #28
Source File: MmtfUtils.java    From biojava with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Convert a four-d matrix to a double array. Row-packed.
 * @param transformationMatrix the input matrix4d object
 * @return the double array (16 long).
 */
public static double[] convertToDoubleArray(Matrix4d transformationMatrix) {
	// Initialise the output array
	double[] outArray = new double[16];
	// Iterate over the matrix
	for(int i=0; i<4; i++){
		for(int j=0; j<4; j++){
			// Now set this element
			outArray[i*4+j] = transformationMatrix.getElement(i,j);
		}
	}
	return outArray;
}
 
Example #29
Source File: Calc.java    From biojava with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Transforms an atom object, given a Matrix4d (i.e. the vecmath library
 * double-precision 4x4 rotation+translation matrix). The transformation
 * Matrix must be a post-multiplication Matrix.
 *
 * @param atom
 * @param m
 */
public static final void transform (Atom atom, Matrix4d m) {

	Point3d p = new Point3d(atom.getX(),atom.getY(),atom.getZ());
	m.transform(p);

	atom.setX(p.x);
	atom.setY(p.y);
	atom.setZ(p.z);
}
 
Example #30
Source File: PoseEntity.java    From Robot-Overlord-App with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 
 * @param arg0 Vector3d of radian rotation values
 */
public void setRotation(Vector3d arg0) {
	Matrix4d m4 = new Matrix4d();
	Matrix3d m3 = MatrixHelper.eulerToMatrix(arg0);
	m4.set(m3);
	m4.setTranslation(getPosition());
	setPose(m4);
}