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

The following examples show how to use javax.vecmath.Matrix3d#rotZ() . 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: Model.java    From Robot-Overlord-App with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Rotate all the vertexes by a given amount
 * @param arg0 amount in degrees to rotate around X,Y, and then Z. 
 */
public void adjustRotation(Vector3d arg0) {
	// generate the pose matrix
	Matrix3d pose = new Matrix3d();
	Matrix3d rotX = new Matrix3d();
	Matrix3d rotY = new Matrix3d();
	Matrix3d rotZ = new Matrix3d();
	rotX.rotX((float)Math.toRadians(arg0.x));
	rotY.rotY((float)Math.toRadians(arg0.y));
	rotZ.rotZ((float)Math.toRadians(arg0.z));
	pose.set(rotX);
	pose.mul(rotY);
	pose.mul(rotZ);
	adjust.set(pose);
	isDirty=true;
}
 
Example 2
Source File: DHTool_GoProCamera.java    From Robot-Overlord-App with GNU General Public License v2.0 6 votes vote down vote up
public DHTool_GoProCamera() {
	super();
	setName("GoPro Camera");
	flags = LinkAdjust.R;
	
	refreshPoseMatrix();
	
	setModelFilename("/Sixi2/gopro/gopro.stl");
	setModelScale(0.1f);
	setModelOrigin(0, 0, 0.5);
	setModelRotation(90, 90, 0);
	
	// adjust the model's position and rotation.
	this.setPosition(new Vector3d(50,0,50));
	Matrix3d m = new Matrix3d();
	m.setIdentity();
	m.rotX(Math.toRadians(90));
	Matrix3d m2 = new Matrix3d();
	m2.setIdentity();
	m2.rotZ(Math.toRadians(90));
	m.mul(m2);
	this.setRotation(m);
}
 
Example 3
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 4
Source File: Icosahedron.java    From biojava with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public Matrix3d getViewMatrix(int index) {
	Matrix3d m = new Matrix3d();
	switch (index) {
	case 0:
		m.setIdentity(); // front vertex-centered
		break;
	case 1:
		m.rotX(-0.6523581397843639); // back face-centered -0.5535743588970415 m.rotX(Math.toRadians(-26));
		break;
	case 2:
		m.rotZ(Math.PI/2);
		Matrix3d m1 = new Matrix3d();
		m1.rotX(-1.0172219678978445);
		m.mul(m1);
		break;
	default:
		throw new IllegalArgumentException("getViewMatrix: index out of range:" + index);
	}
	return m;
}
 
Example 5
Source File: Prism.java    From biojava with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Returns the vertices of an n-fold polygon of given radius and center
 * @return
 */
@Override
public Point3d[] getVertices() {
	Point3d[] polygon = new Point3d[2*n];
	Matrix3d m = new Matrix3d();

	Point3d center = new Point3d(0, 0, height/2);

	for (int i = 0; i < n; i++) {
		polygon[i] = new Point3d(0, circumscribedRadius, 0);
		m.rotZ(i*2*Math.PI/n);
		m.transform(polygon[i]);
		polygon[n+i] = new  Point3d(polygon[i]);
		polygon[i].sub(center);
		polygon[n+i].add(center);
	}

	return polygon;
}
 
Example 6
Source File: Octahedron.java    From biojava with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public Matrix3d getViewMatrix(int index) {
	Matrix3d m = new Matrix3d();
	switch (index) {
	case 0:
		m.setIdentity(); // C4 vertex-centered
		break;
	case 1:
		m.rotX(-0.5 * TETRAHEDRAL_ANGLE); // C3 face-centered  2.0*Math.PI/3
		Matrix3d m1 = new Matrix3d();
		m1.rotZ(Math.PI/4);
		m.mul(m1);
		break;
	case 2:
		m.rotY(Math.PI/4); // side face-centered
		break;
	default:
		throw new IllegalArgumentException("getViewMatrix: index out of range:" + index);
	}
	return m;
}
 
Example 7
Source File: Quadcopter.java    From jMAVSim with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Generic quadcopter constructor.
 *
 * @param world          world where to place the vehicle
 * @param modelName      filename of model to load, in .obj format
 * @param orientation    "x" or "+"
 * @param armLength      length of arm from center
 * @param rotorThrust    full thrust of one rotor
 * @param rotorTorque    torque at full thrust of one rotor
 * @param rotorTimeConst spin-up time of rotor
 * @param rotorsOffset   rotors positions offset from gravity center
 * @throws FileNotFoundException if .obj model file not found
 */
public Quadcopter(World world, String modelName, String orientation, double armLength, double rotorThrust,
                  double rotorTorque, double rotorTimeConst, Vector3d rotorsOffset) throws FileNotFoundException {
    super(world, modelName);
    rotorPositions[0] = new Vector3d(0.0, armLength, 0.0);
    rotorPositions[1] = new Vector3d(0.0, -armLength, 0.0);
    rotorPositions[2] = new Vector3d(armLength, 0.0, 0.0);
    rotorPositions[3] = new Vector3d(-armLength, 0.0, 0.0);
    if (orientation.equals("x") || orientation.equals("X")) {
        Matrix3d r = new Matrix3d();
        r.rotZ(-Math.PI / 4);
        for (int i = 0; i < rotorsNum; i++) {
            r.transform(rotorPositions[i]);
        }
    } else if (orientation.equals("+")) {
    } else {
        throw new RuntimeException("Unknown orientation: " + orientation);
    }
    for (int i = 0; i < rotors.length; i++) {
        rotorPositions[i].add(rotorsOffset);
        Rotor rotor = rotors[i];
        rotor.setFullThrust(rotorThrust);
        rotor.setFullTorque(i < 2 ? -rotorTorque : rotorTorque);
        rotor.setTimeConstant(rotorTimeConst);
    }
}
 
Example 8
Source File: Icosahedron.java    From biojava with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public Point3d[] getVertices() {
	Point3d[] icosahedron = new Point3d[12];
	// see http://answers.yahoo.com/question/index?qid=20080108041441AAJCjEu
	double c = circumscribedRadius * 1 / Math.sqrt(5);
	double s = 2 * c; // golden ratio
	double c1 = Math.sqrt((3-Math.sqrt(5))/8); // cos(2Pi/5)
	double s1 = Math.sqrt((5+Math.sqrt(5))/8); // sin(2Pi/5)
	double c2 = Math.sqrt((3+Math.sqrt(5))/8); // cos(Pi/5)
	double s2 = Math.sqrt((5-Math.sqrt(5))/8); // sin(Pi/5)

	icosahedron[0] = new Point3d(0, 0, circumscribedRadius);
	icosahedron[1] = new Point3d(s, 0, c);
	icosahedron[2] = new Point3d(s*c1, s*s1, c);
	icosahedron[3] = new Point3d(-s*c2, s*s2, c);
	icosahedron[4] = new Point3d(-s*c2, -s*s2, c);
	icosahedron[5] = new Point3d(s*c1, -s*s1, c);
	for (int i = 0; i < 6; i++) {
		icosahedron[i+6] = new Point3d(icosahedron[i]);
		icosahedron[i+6].negate();
	}

	Matrix3d m = new Matrix3d();
	m.rotZ(Math.PI/10);
	for (Point3d p: icosahedron) {
		m.transform(p);
	}

	return icosahedron;
}
 
Example 9
Source File: Prism.java    From biojava with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Returns the vertices of an n-fold polygon of given radius and center
 * @return
 */
public static Point3d[] getPolygonVertices(int n, double radius, Point3d center) {
	Point3d[] polygon = new Point3d[n];
	Matrix3d m = new Matrix3d();

	for (int i = 0; i < n; i++) {
		polygon[i] = new Point3d(0, radius, 0);
		m.rotZ(i*2*Math.PI/n);
		m.transform(polygon[i]);
		polygon[i].add(center);
	}
	return polygon;
}
 
Example 10
Source File: Hexacopter.java    From jMAVSim with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Generic hexacopter constructor.
 *
 * @param world          world where to place the vehicle
 * @param modelName      filename of model to load, in .obj format
 * @param orientation    "x" or "+"
 * @param armLength      length of arm from center
 * @param rotorThrust    full thrust of one rotor
 * @param rotorTorque    torque at full thrust of one rotor
 * @param rotorTimeConst spin-up time of rotor
 * @param rotorsOffset   rotors positions offset from gravity center
 * @throws FileNotFoundException if .obj model file not found
 */
public Hexacopter(World world, String modelName, String orientation, double armLength, double rotorThrust,
                  double rotorTorque, double rotorTimeConst, Vector3d rotorsOffset) throws FileNotFoundException {
    super(world, modelName);
    rotorPositions[0] = new Vector3d(armLength, 0.0, 0.0);
    rotorPositions[1] = new Vector3d(-armLength, 0.0, 0.0);
    rotorPositions[2] = new Vector3d(-armLength * Math.cos(Math.PI / 3), -armLength * Math.sin(Math.PI / 3), 0.0);
    rotorPositions[3] = new Vector3d(armLength * Math.cos(Math.PI / 3), armLength * Math.sin(Math.PI / 3), 0.0);
    rotorPositions[4] = new Vector3d(armLength * Math.cos(Math.PI / 3), -armLength * Math.sin(Math.PI / 3), 0.0);
    rotorPositions[5] = new Vector3d(-armLength * Math.cos(Math.PI / 3), armLength * Math.sin(Math.PI / 3), 0.0);
    if (orientation.equals("x") || orientation.equals("X")) {
        Matrix3d r = new Matrix3d();
        r.rotZ(Math.PI / 2);
        for (int i = 0; i < rotorsNum; i++) {
            r.transform(rotorPositions[i]);
        }
    } else if (orientation.equals("+")) {
    } else {
        throw new RuntimeException("Unknown orientation: " + orientation);
    }
    for (int i = 0; i < rotors.length; i++) {
        rotorPositions[i].add(rotorsOffset);
        Rotor rotor = rotors[i];
        rotor.setFullThrust(rotorThrust);
        rotor.setFullTorque((i == 1 || i == 3 || i == 4) ? -rotorTorque : rotorTorque);
        rotor.setTimeConstant(rotorTimeConst);
    }
}
 
Example 11
Source File: DHTool_Gripper.java    From Robot-Overlord-App with GNU General Public License v2.0 4 votes vote down vote up
public DHTool_Gripper() {
	super();
	setLetter("T");
	setName("Gripper");
	refreshPoseMatrix();
	
	gripperServoAngle=90;
	interpolatePoseT=1;
	startT=endT=gripperServoAngle;
	
	setModelFilename("/Sixi2/beerGripper/base.stl");
	setModelScale(0.1f);
	setModelOrigin(-1,0,4.15);
	setModelRotation(0,180,90);
	

	Matrix3d r = new Matrix3d();
	r.setIdentity();
	r.rotX(Math.toRadians(180));
	Matrix3d r2 = new Matrix3d();
	r2.setIdentity();
	r2.rotZ(Math.toRadians(90));
	r.mul(r2);
	this.setRotation(r);
	
	// 4 bars
	addChild(subComponents[0]=new DHLink());
	addChild(subComponents[1]=new DHLink());
	addChild(subComponents[2]=new DHLink());
	addChild(subComponents[3]=new DHLink());
	subComponents[0].setModelFilename("/Sixi2/beerGripper/linkage.stl");
	subComponents[0].setModelScale(0.1f);
	subComponents[1].set(subComponents[0]);
	subComponents[2].set(subComponents[0]);
	subComponents[3].set(subComponents[0]);
	subComponents[0].setPosition(new Vector3d(2.7/2, 0, 4.1));
	subComponents[1].setPosition(new Vector3d(1.1/2, 0, 5.9575));
	subComponents[2].setPosition(new Vector3d(-2.7/2, 0, 4.1));
	subComponents[3].setPosition(new Vector3d(-1.1/2, 0, 5.9575));
	
	// 2 finger tips
	addChild(subComponents[4]=new DHLink());
	subComponents[4].setModelFilename("/Sixi2/beerGripper/finger.stl");
	subComponents[4].setModelScale(0.1f);
	addChild(subComponents[5]=new DHLink());
	subComponents[5].set(subComponents[4]);
	
	wasGripping=false;
}