Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Matrix multiplication using Jama Library
- //https://math.nist.gov/javanumerics/jama/
- import Jama.*;
- float[] eulerToAxisRotations(float roll, float pitch, float yaw) {
- double[][] a = {
- {1, 0, 0},
- {0, cos(roll), -sin(roll)},
- {0, sin(roll), cos(roll)}
- };
- double[][] b = {
- {cos(pitch), 0, sin(pitch)},
- {0, 1, 0},
- {-sin(pitch), 0, cos(pitch)}
- };
- double[][] c = {
- {cos(yaw), -sin(yaw), 0},
- {sin(yaw), cos(yaw), 0},
- {0, 0, 1}
- };
- Matrix rollMatrix = new Matrix(a);
- Matrix pitchMatrix = new Matrix(b);
- Matrix yawMatrix = new Matrix(c);
- Matrix rMatrix = rollMatrix.times(pitchMatrix).times(yawMatrix);
- float theta = acos((((float)rMatrix.get(0,0) + (float)rMatrix.get(1,1) + (float)rMatrix.get(2, 2)) - 1) / 2);
- float multi = 1 / (2 * sin(theta));
- float rx = multi * ((float)rMatrix.get(2,1) - (float)rMatrix.get(1,2)) * theta;
- float ry = multi * ((float)rMatrix.get(0,2) - (float)rMatrix.get(2,0)) * theta;
- float rz = multi * ((float)rMatrix.get(1,0) - (float)rMatrix.get(0,1)) * theta;
- float[] r = {rx, ry, rz};
- return r;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement