Java Code Examples for javax.vecmath.Matrix3d#transpose()

The following examples show how to use javax.vecmath.Matrix3d#transpose() . 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: CameraEntity.java    From Robot-Overlord-App with GNU General Public License v2.0 6 votes vote down vote up
protected Matrix3d buildPanTiltMatrix(double panDeg,double tiltDeg) {
	Matrix3d a = new Matrix3d();
	Matrix3d b = new Matrix3d();
	Matrix3d c = new Matrix3d();
	a.rotZ(Math.toRadians(panDeg));
	b.rotX(Math.toRadians(-tiltDeg));
	c.mul(b,a);

	right.x=c.m00;
	right.y=c.m01;
	right.z=c.m02;

	up.x=c.m10;
	up.y=c.m11;
	up.z=c.m12;
	
	forward.x=c.m20;
	forward.y=c.m21;
	forward.z=c.m22;
	
	c.transpose();
	
	return c;
}
 
Example 2
Source File: PhysicsCalculations.java    From Valkyrien-Skies with Apache License 2.0 5 votes vote down vote up
/**
 * Generates the rotated moment of inertia tensor with the body; uses the following formula: I'
 * = R * I * R-transpose; where I' is the rotated inertia, I is un-rotated interim, and R is the
 * rotation matrix.
 */
private void calculateFramedMOITensor() {
    double[] framedMOI = RotationMatrices.getZeroMatrix(3);

    // Copy the rotation matrix, ignore the translation and scaling parts.
    Matrix3d rotationMatrix = getParent().getShipTransformationManager()
        .getCurrentPhysicsTransform().createRotationMatrix(TransformType.SUBSPACE_TO_GLOBAL);

    Matrix3d inertiaBodyFrame = new Matrix3d(gameMoITensor);
    // The product of the overall rotation matrix with the inertia tensor.
    inertiaBodyFrame.mul(rotationMatrix);
    rotationMatrix.transpose();
    // The product of the inertia tensor multiplied with the transpose of the
    // rotation transpose.
    inertiaBodyFrame.mul(rotationMatrix);
    framedMOI[0] = inertiaBodyFrame.m00;
    framedMOI[1] = inertiaBodyFrame.m01;
    framedMOI[2] = inertiaBodyFrame.m02;
    framedMOI[3] = inertiaBodyFrame.m10;
    framedMOI[4] = inertiaBodyFrame.m11;
    framedMOI[5] = inertiaBodyFrame.m12;
    framedMOI[6] = inertiaBodyFrame.m20;
    framedMOI[7] = inertiaBodyFrame.m21;
    framedMOI[8] = inertiaBodyFrame.m22;

    physMOITensor = framedMOI;
    setPhysInvMOITensor(RotationMatrices.inverse3by3(framedMOI));
}
 
Example 3
Source File: MatrixHelper.java    From Robot-Overlord-App with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Confirms that this matrix is a rotation matrix.  Matrix A * transpose(A) should be the Identity.
 * See also https://www.learnopencv.com/rotation-matrix-to-euler-angles/
 * @param mat
 * @return
 */
public static boolean isRotationMatrix(Matrix3d mat) {
	Matrix3d m1 = new Matrix3d(mat);
	Matrix3d m2 = new Matrix3d();
	m2.transpose(m1);
	m1.mul(m2);
	m2.setIdentity();
	return m1.epsilonEquals(m2, 1e-6);
}
 
Example 4
Source File: SimpleSensors.java    From jMAVSim with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public Vector3d getAcc() {
    Vector3d accBody = new Vector3d(object.getAcceleration());
    accBody.sub(object.getWorld().getEnvironment().getG());
    Matrix3d rot = new Matrix3d(object.getRotation());
    rot.transpose();
    rot.transform(accBody);
    return accBody;
}
 
Example 5
Source File: SimpleSensors.java    From jMAVSim with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public Vector3d getMag() {
    Vector3d mag = new Vector3d(object.getWorld().getEnvironment().getMagField(object.getPosition()));
    Matrix3d rot = new Matrix3d(object.getRotation());
    rot.transpose();
    rot.transform(mag);
    return mag;
}
 
Example 6
Source File: Sixi2Model.java    From Robot-Overlord-App with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Use Forward Kinematics to approximate the Jacobian matrix for Sixi.
 * See also https://robotacademy.net.au/masterclass/velocity-kinematics-in-3d/?lesson=346
 */
public double [][] approximateJacobian(DHKeyframe keyframe) {
	double [][] jacobian = new double[6][6];
	
	double ANGLE_STEP_SIZE_DEGREES=0.5;  // degrees
	
	DHKeyframe oldPoseFK = getIKSolver().createDHKeyframe();
	getPoseFK(oldPoseFK);
	
	setPoseFK(keyframe);
	Matrix4d T = endEffector.getPoseWorld();
	
	DHKeyframe newPoseFK = getIKSolver().createDHKeyframe();
	int i=0;
	// for all adjustable joints
	for( DHLink link : links ) {
		if(link.flags == LinkAdjust.NONE) continue;
		
		// use anglesB to get the hand matrix after a tiny adjustment on one joint.
		newPoseFK.set(keyframe);
		newPoseFK.fkValues[i]+=ANGLE_STEP_SIZE_DEGREES;
		setPoseFK(newPoseFK);
		// Tnew will be different from T because of the changes in setPoseFK().
		Matrix4d Tnew = endEffector.getPoseWorld();
		
		// use the finite difference in the two matrixes
		// aka the approximate the rate of change (aka the integral, aka the velocity)
		// in one column of the jacobian matrix at this position.
		Matrix4d dT = new Matrix4d();
		dT.sub(Tnew,T);
		dT.mul(1.0/Math.toRadians(ANGLE_STEP_SIZE_DEGREES));
		
		jacobian[i][0]=dT.m03;
		jacobian[i][1]=dT.m13;
		jacobian[i][2]=dT.m23;

		// find the rotation part
		// these initialT and initialTd were found in the comments on
		// https://robotacademy.net.au/masterclass/velocity-kinematics-in-3d/?lesson=346
		// and used to confirm that our skew-symmetric matrix match theirs.
		/*
		double[] initialT = {
				 0,  0   , 1   ,  0.5963,
				 0,  1   , 0   , -0.1501,
				-1,  0   , 0   , -0.01435,
				 0,  0   , 0   ,  1 };
		double[] initialTd = {
				 0, -0.01, 1   ,  0.5978,
				 0,  1   , 0.01, -0.1441,
				-1,  0   , 0   , -0.01435,
				 0,  0   , 0   ,  1 };
		T.set(initialT);
		Td.set(initialTd);
		dT.sub(Td,T);
		dT.mul(1.0/Math.toRadians(ANGLE_STEP_SIZE_DEGREES));//*/
		
		//Log.message("T="+T);
		//Log.message("Td="+Td);
		//Log.message("dT="+dT);
		Matrix3d T3 = new Matrix3d(
				T.m00,T.m01,T.m02,
				T.m10,T.m11,T.m12,
				T.m20,T.m21,T.m22);
		//Log.message("R="+R);
		Matrix3d dT3 = new Matrix3d(
				dT.m00,dT.m01,dT.m02,
				dT.m10,dT.m11,dT.m12,
				dT.m20,dT.m21,dT.m22);
		//Log.message("dT3="+dT3);
		Matrix3d skewSymmetric = new Matrix3d();
		
		T3.transpose();  // inverse of a rotation matrix is its transpose
		skewSymmetric.mul(dT3,T3);
		
		//Log.message("SS="+skewSymmetric);
		//[  0 -Wz  Wy]
		//[ Wz   0 -Wx]
		//[-Wy  Wx   0]
		
		jacobian[i][3]=skewSymmetric.m12;
		jacobian[i][4]=skewSymmetric.m20;
		jacobian[i][5]=skewSymmetric.m01;
		
		++i;
	}
	
	// undo our changes.
	setPoseFK(oldPoseFK);
	
	return jacobian;
}