Created
February 14, 2018 07:37
-
-
Save haleyjd/f05f12fc67986ee5f9954b9b0a6dfa7b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** assumes q1 is a normalised quaternion */ | |
public void set(Quat4d q1) { | |
double test = q1.x*q1.y + q1.z*q1.w; | |
if (test > 0.499) { // singularity at north pole | |
heading = 2 * atan2(q1.x,q1.w); | |
attitude = Math.PI/2; | |
bank = 0; | |
return; | |
} | |
if (test < -0.499) { // singularity at south pole | |
heading = -2 * atan2(q1.x,q1.w); | |
attitude = - Math.PI/2; | |
bank = 0; | |
return; | |
} | |
double sqx = q1.x*q1.x; | |
double sqy = q1.y*q1.y; | |
double sqz = q1.z*q1.z; | |
heading = atan2(2*q1.y*q1.w-2*q1.x*q1.z , 1 - 2*sqy - 2*sqz); | |
attitude = asin(2*test); | |
bank = atan2(2*q1.x*q1.w-2*q1.y*q1.z , 1 - 2*sqx - 2*sqz) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment