Advertisement
itblanco

Euler to Axis-angles

Feb 13th, 2020
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.12 KB | None | 0 0
  1. //Matrix multiplication using Jama Library
  2. //https://math.nist.gov/javanumerics/jama/
  3. import Jama.*;
  4.  
  5. float[] eulerToAxisRotations(float roll, float pitch, float yaw) {
  6.   double[][] a = {
  7.     {1, 0, 0},
  8.     {0, cos(roll), -sin(roll)},
  9.     {0, sin(roll), cos(roll)}
  10.   };
  11.   double[][] b = {
  12.     {cos(pitch), 0, sin(pitch)},
  13.     {0, 1, 0},
  14.     {-sin(pitch), 0, cos(pitch)}
  15.   };
  16.   double[][] c = {
  17.     {cos(yaw), -sin(yaw), 0},
  18.     {sin(yaw), cos(yaw), 0},
  19.     {0, 0, 1}
  20.   };
  21.  
  22.   Matrix rollMatrix = new Matrix(a);
  23.   Matrix pitchMatrix = new Matrix(b);
  24.   Matrix yawMatrix = new Matrix(c);
  25.  
  26.   Matrix rMatrix = rollMatrix.times(pitchMatrix).times(yawMatrix);
  27.  
  28.   float theta = acos((((float)rMatrix.get(0,0) + (float)rMatrix.get(1,1) + (float)rMatrix.get(2, 2)) - 1) / 2);
  29.   float multi = 1 / (2 * sin(theta));
  30.  
  31.   float rx = multi * ((float)rMatrix.get(2,1) - (float)rMatrix.get(1,2)) * theta;
  32.   float ry = multi * ((float)rMatrix.get(0,2) - (float)rMatrix.get(2,0)) * theta;
  33.   float rz = multi * ((float)rMatrix.get(1,0) - (float)rMatrix.get(0,1)) * theta;
  34.  
  35.   float[] r = {rx, ry, rz};
  36.   return r;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement