Java Code Examples for javax.vecmath.Matrix4d#transform()

The following examples show how to use javax.vecmath.Matrix4d#transform() . 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: 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 2
Source File: DragBallEntity.java    From Robot-Overlord-App with GNU General Public License v2.0 5 votes vote down vote up
/**
 * transform a world-space point to the ball's current frame of reference
 * @param pointInWorldSpace the world space point
 * @return the transformed Vector3d
 */
public Vector3d getPickPointInFOR(Vector3d pointInWorldSpace,Matrix4d frameOfReference) {
	Matrix4d iMe = new Matrix4d(frameOfReference);
	iMe.m30=iMe.m31=iMe.m32=0;
	iMe.invert();
	Vector3d pickPointInBallSpace = new Vector3d(pointInWorldSpace);
	pickPointInBallSpace.sub(this.getPosition());
	iMe.transform(pickPointInBallSpace);
	return pickPointInBallSpace;
}
 
Example 3
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 4
Source File: Robot_Phybot.java    From Robot-Overlord-App with GNU General Public License v2.0 4 votes vote down vote up
public void setupModels(DHRobotEntity robot) {
	material = new MaterialEntity();
	float r=0.75f;
	float g=0.15f;
	float b=0.15f;
	material.setDiffuseColor(r,g,b,1);
	
	try {
		robot.links.get(0).setModelFilename("/Sixi/anchor.stl");
		robot.links.get(1).setModelFilename("/Sixi/shoulder.stl");
		robot.links.get(2).setModelFilename("/Sixi/bicep.stl");
		robot.links.get(3).setModelFilename("/Sixi/elbow.stl");
		robot.links.get(5).setModelFilename("/Sixi/forearm.stl");
		robot.links.get(6).setModelFilename("/Sixi/wrist.stl");
		robot.links.get(7).setModelFilename("/Sixi/hand.stl");

		for( DHLink link : robot.links ) link.setModelScale(0.1f);
		robot.links.get(1).getModel().adjustOrigin(new Vector3d(0, 0, -25));
		robot.links.get(2).getModel().adjustOrigin(new Vector3d(0, -5, -25));
		robot.links.get(2).getModel().adjustRotation(new Vector3d(-11.3,0,0));
		
		robot.links.get(5).getModel().adjustOrigin(new Vector3d(0, 0, -60));
		robot.links.get(6).getModel().adjustOrigin(new Vector3d(0, 0, -70));
		robot.links.get(7).getModel().adjustOrigin(new Vector3d(0, 0, -74));

		Matrix4d rot = new Matrix4d();
		Matrix4d rotX = new Matrix4d();
		Matrix4d rotY = new Matrix4d();
		Matrix4d rotZ = new Matrix4d();
		rot.setIdentity();
		rotX.rotX((float)Math.toRadians(90));
		rotY.rotY((float)Math.toRadians(0));
		rotZ.rotZ((float)Math.toRadians(0));
		rot.set(rotX);
		rot.mul(rotY);
		rot.mul(rotZ);
		Matrix4d pose = new Matrix4d(rot);
		Vector3d adjustPos = new Vector3d(0, 5, -50);
		pose.transform(adjustPos);
		
		robot.links.get(3).getModel().adjustOrigin(adjustPos);
		robot.links.get(3).getModel().adjustRotation(new Vector3d(90, 0, 0));
	} catch (Exception e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
}
 
Example 5
Source File: HelixSolver.java    From biojava with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Returns a permutation of subunit indices for the given helix
 * transformation. An index of -1 is used to indicate subunits that do not
 * superpose onto any other subunit.
 *
 * @param transformation
 * @return
 */
private List<Integer> getPermutation(Matrix4d transformation) {
	double rmsdThresholdSq = Math
			.pow(this.parameters.getRmsdThreshold(), 2);

	List<Point3d> centers = subunits.getOriginalCenters();
	List<Integer> seqClusterId = subunits.getClusterIds();

	List<Integer> permutations = new ArrayList<Integer>(centers.size());
	double[] dSqs = new double[centers.size()];
	boolean[] used = new boolean[centers.size()];
	Arrays.fill(used, false);

	for (int i = 0; i < centers.size(); i++) {
		Point3d tCenter = new Point3d(centers.get(i));
		transformation.transform(tCenter);
		int permutation = -1;
		double minDistSq = Double.MAX_VALUE;
		for (int j = 0; j < centers.size(); j++) {
			if (seqClusterId.get(i) == seqClusterId.get(j)) {
				if (!used[j]) {
					double dSq = tCenter.distanceSquared(centers.get(j));
					if (dSq < minDistSq && dSq <= rmsdThresholdSq) {
						minDistSq = dSq;
						permutation = j;
						dSqs[j] = dSq;
					}
				}
			}
		}
		// can't map to itself
		if (permutations.size() == permutation) {
			permutation = -1;
		}

		if (permutation != -1) {
			used[permutation] = true;
		}

		permutations.add(permutation);
	}

	return permutations;
}
 
Example 6
Source File: RotationSolver.java    From biojava with GNU Lesser General Public License v2.1 4 votes vote down vote up
private void solve() {
	initialize();

	int maxSymOps = subunits.getSubunitCount();

	boolean isSpherical = isSpherical();

	// for cases with icosahedral symmetry n cannot be higher than 60, should check for spherical symmetry here
	// isSpherical check added 08-04-11
	if (maxSymOps % 60 == 0 && isSpherical) {
		maxSymOps = 60;
	 }

	AxisAngle4d sphereAngle = new AxisAngle4d();
	Matrix4d transformation = new Matrix4d();

	int n = subunits.getSubunitCount();

	int sphereCount = SphereSampler.getSphereCount();

	List<Double> angles = getAngles();

	for (int i = 0; i < sphereCount; i++) {
		// Sampled orientation
		//TODO The SphereSampler samples 4D orientation space. We really
		// only need to sample 3D unit vectors, since we use limited
		// angles. -SB
		SphereSampler.getAxisAngle(i, sphereAngle);

		// Each valid rotation angle
		for (double angle : angles) {
			// apply rotation
			sphereAngle.angle = angle;
			transformation.set(sphereAngle);
			// Make sure matrix element m33 is 1.0. It's not on Linux.
			transformation.setElement(3, 3, 1.0);
			for (int j = 0; j < n; j++) {
				transformedCoords[j].set(originalCoords[j]);
				transformation.transform(transformedCoords[j]);
			}

			// get permutation of subunits and check validity/uniqueness
			List<Integer> permutation = getPermutation();
//              System.out.println("Rotation Solver: permutation: " + i + ": " + permutation);

			// check if novel
			if ( evaluatedPermutations.containsKey(permutation)) {
				continue; //either invalid or already added
			}

			Rotation newPermutation = isValidPermutation(permutation);
			if (newPermutation != null) {
				completeRotationGroup(newPermutation);
			}

			// check if all symmetry operations have been found.
			if (rotations.getOrder() >= maxSymOps) {
				return;
			}
		}
	}
}
 
Example 7
Source File: QuatSuperpositionScorer.java    From biojava with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Returns minimum, mean, and maximum RMSD and TM-Score for two superimposed sets of subunits
 *
 * TM score: Yang Zhang and Jeffrey Skolnick, PROTEINS: Structure, Function, and Bioinformatics 57:702–710 (2004)
 * @param subunits subunits to be scored
 * @param transformation transformation matrix
 * @param permutations permutation that determines which subunits are superposed
 * @return
 */
public static QuatSymmetryScores calcScores(QuatSymmetrySubunits subunits, Matrix4d transformation, List<Integer> permutation) {
	QuatSymmetryScores scores = new QuatSymmetryScores();

	double minTm = Double.MAX_VALUE;
	double maxTm = Double.MIN_VALUE;
	double minRmsd = Double.MAX_VALUE;
	double maxRmsd = Double.MIN_VALUE;

	double totalSumTm = 0;
	double totalSumDsq = 0;
	double totalLength = 0;

	Point3d t = new Point3d();
	List<Point3d[]> traces = subunits.getTraces();

	// loop over the Calpha atoms of all subunits
	for (int i = 0; i < traces.size(); i++) {
		// in helical systems not all permutations involve all subunit. -1 indicates subunits that should not be permuted.
		 if (permutation.get(i) == -1) {
			continue;
		 }
		// get original subunit
		Point3d[] orig = traces.get(i);
		totalLength += orig.length;

		// get permuted subunit
		Point3d[] perm = traces.get(permutation.get(i));

		// calculate TM specific parameters
		int tmLen = Math.max(orig.length, 17);  // don't let d0 get negative with short sequences
		double d0 = 1.24 * Math.cbrt(tmLen - 15.0) - 1.8;
		double d0Sq = d0 * d0;

		double sumTm = 0;
		double sumDsq = 0;
		for (int j = 0; j < orig.length; j++) {
			// transform coordinates of the permuted subunit
			t.set(perm[j]);
			transformation.transform(t);

			double dSq = orig[j].distanceSquared(t);
			sumTm += 1.0/(1.0 + dSq/d0Sq);
			sumDsq += dSq;
		}

		// scores for individual subunits
		double sTm = sumTm/tmLen;
		minTm = Math.min(minTm, sTm);
		maxTm = Math.max(maxTm, sTm);

		double sRmsd = Math.sqrt(sumDsq/orig.length);
		minRmsd = Math.min(minRmsd,  sRmsd);
		maxRmsd = Math.max(maxRmsd,  sRmsd);

		totalSumTm += sumTm;
		totalSumDsq += sumDsq;
	}

	// save scores for individual subunits
	scores.setMinRmsd(minRmsd);
	scores.setMaxRmsd(maxRmsd);
	scores.setMinTm(minTm);
	scores.setMaxTm(maxTm);

	// save mean scores over all subunits
	scores.setTm(totalSumTm/totalLength);
	scores.setRmsd(Math.sqrt(totalSumDsq/totalLength));

	// add intra subunit scores
	calcIntrasubunitScores(subunits, transformation, permutation, scores);

	return scores;
}
 
Example 8
Source File: CalcPoint.java    From biojava with GNU Lesser General Public License v2.1 2 votes vote down vote up
/**
 * Transform all points with a 4x4 transformation matrix.
 *
 * @param rotTrans
 *            4x4 transformation matrix
 * @param x
 *            array of points. Point objects will be modified
 */
public static void transform(Matrix4d rotTrans, Point3d[] x) {
	for (Point3d p : x) {
		rotTrans.transform(p);
	}
}