-
Couldn't load subscription status.
- Fork 605
add 3x3 rotation matrix to quaternion function #265
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -453,6 +453,40 @@ static inline void TFN(s_mat_to_xyz)(const TNAME M[16], TNAME xyz[3]) | |
| xyz[2] = M[11]; | ||
| } | ||
|
|
||
| static inline void TFN(s_mat33_to_quat)(const TNAME M[9], TNAME q[4]) | ||
| { | ||
| double T = M[0] + M[4] + M[8] + 1.0; | ||
| double S; | ||
|
|
||
| if (T > 0.0000001) { | ||
| S = sqrt(T) * 2; | ||
| q[0] = (TNAME)(0.25 * S); | ||
| q[1] = (TNAME)((M[7] - M[5]) / S); | ||
| q[2] = (TNAME)((M[2] - M[6]) / S); | ||
| q[3] = (TNAME)((M[3] - M[1]) / S); | ||
| } else if (M[0] > M[4] && M[0] > M[8]) { // Column 0: | ||
| S = sqrt(1.0 + M[0] - M[4] - M[8]) * 2; | ||
| q[0] = (TNAME)((M[7] - M[5]) / S); | ||
| q[1] = (TNAME)(0.25 * S); | ||
| q[2] = (TNAME)((M[3] + M[1]) / S); | ||
| q[3] = (TNAME)((M[2] + M[6]) / S); | ||
| } else if (M[4] > M[8]) { // Column 1: | ||
| S = sqrt(1.0 + M[4] - M[0] - M[8]) * 2; | ||
| q[0] = (TNAME)((M[2] - M[6]) / S); | ||
| q[1] = (TNAME)((M[3] + M[1]) / S); | ||
| q[2] = (TNAME)(0.25 * S); | ||
| q[3] = (TNAME)((M[7] + M[5]) / S); | ||
| } else { // Column 2: | ||
| S = sqrt(1.0 + M[8] - M[0] - M[4]); | ||
| q[0] = (TNAME)((M[3] - M[1]) / S); | ||
| q[1] = (TNAME)((M[2] + M[6]) / S); | ||
| q[2] = (TNAME)((M[7] + M[5]) / S); | ||
| q[3] = (TNAME)(0.25 * S); | ||
| } | ||
|
Comment on lines
+461
to
+485
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's try to avoid code duplication with |
||
|
|
||
| TFN(s_normalize)(q, 4, q); | ||
| } | ||
|
|
||
| static inline void TFN(s_mat_to_quat)(const TNAME M[16], TNAME q[4]) | ||
| { | ||
| double T = M[0] + M[5] + M[10] + 1.0; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe call this function "rot_mat_to_quat"? "mat33" sounds as if it accepts any 3x3 matrix. Do you think we need to check that the matrix provided is actually a rotation matrix?