Merge pull request #6607 from andzdroid/patch-5

core/math/linalg: Fix negated quaternions in angle_from_quaternion
This commit is contained in:
gingerBill
2026-04-28 11:11:44 +01:00
committed by GitHub

View File

@@ -512,7 +512,8 @@ quaternion_angle_axis :: proc{
@(require_results)
angle_from_quaternion_f16 :: proc "contextless" (q: Quaternionf16) -> f16 {
if abs(q.w) > math.SQRT_THREE*0.5 {
return math.asin(math.sqrt(q.x*q.x + q.y*q.y + q.z*q.z)) * 2
angle := math.asin(math.sqrt(q.x*q.x + q.y*q.y + q.z*q.z)) * 2
return q.w < 0 ? math.TAU - angle : angle
}
return math.acos(q.w) * 2
@@ -520,7 +521,8 @@ angle_from_quaternion_f16 :: proc "contextless" (q: Quaternionf16) -> f16 {
@(require_results)
angle_from_quaternion_f32 :: proc "contextless" (q: Quaternionf32) -> f32 {
if abs(q.w) > math.SQRT_THREE*0.5 {
return math.asin(math.sqrt(q.x*q.x + q.y*q.y + q.z*q.z)) * 2
angle := math.asin(math.sqrt(q.x*q.x + q.y*q.y + q.z*q.z)) * 2
return q.w < 0 ? math.TAU - angle : angle
}
return math.acos(q.w) * 2
@@ -528,7 +530,8 @@ angle_from_quaternion_f32 :: proc "contextless" (q: Quaternionf32) -> f32 {
@(require_results)
angle_from_quaternion_f64 :: proc "contextless" (q: Quaternionf64) -> f64 {
if abs(q.w) > math.SQRT_THREE*0.5 {
return math.asin(math.sqrt(q.x*q.x + q.y*q.y + q.z*q.z)) * 2
angle := math.asin(math.sqrt(q.x*q.x + q.y*q.y + q.z*q.z)) * 2
return q.w < 0 ? math.TAU - angle : angle
}
return math.acos(q.w) * 2