Skip to content

Commit

Permalink
Added conversion eulerAnglesByQuaternion
Browse files Browse the repository at this point in the history
  • Loading branch information
DrTon committed Jan 5, 2015
1 parent 3a8b542 commit a631983
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/me/drton/jmavlib/conversion/RotationConversion.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,12 @@ public static Matrix rotationMatrixByEulerAngles(double roll, double pitch, doub
R.set(2, 2, cos(roll) * cos(pitch));
return R;
}

public static double[] eulerAnglesByQuaternion(double[] q) {
return new double[]{
Math.atan2(2.0 * (q[0] * q[1] + q[2] * q[3]), 1.0 - 2.0 * (q[1] * q[1] + q[2] * q[2])),
Math.asin(2 * (q[0] * q[2] - q[3] * q[1])),
Math.atan2(2.0 * (q[0] * q[3] + q[1] * q[2]), 1.0 - 2.0 * (q[2] * q[2] + q[3] * q[3])),
};
}
}

0 comments on commit a631983

Please sign in to comment.