odin-lang / Odin

Odin Programming Language
https://odin-lang.org
BSD 3-Clause "New" or "Revised" License
6.64k stars 583 forks source link

`linalg.angle_axis_from_quaternion` returns `[NaN, NaN, NaN]` axis for identity quaternion #3726

Closed brianpmaher closed 3 months ago

brianpmaher commented 3 months ago

Context

    Odin:    dev-2024-06:1945218f6
    OS:      Windows 10 Professional (version: 22H2), build 19045.4412
    CPU:     AMD Ryzen 9 3900X 12-Core Processor
    RAM:     65435 MiB
    Backend: LLVM 17.0.1

Expected Behavior

Axis should be valid for an identity quaternion from linalg.angle_axis_from_quaternion.

I'm not familiar enough with the math to know what value makes sense here. Maybe 0,0,0 or 1,0,0 or something else. But I would expect an identity quaternion to still have a valid axis.

Current Behavior

Axis is [NaN, NaN, NaN] for identity quaternion from linalg.angle_axis_from_quaternion

Failure Information (for bugs)

image

Steps to Reproduce

Here's a minimal program that reproduces the issue:

package main

import "core:fmt"
import la "core:math/linalg"

main :: proc() {
    angle, axis := la.angle_axis_from_quaternion(la.QUATERNIONF32_IDENTITY)
    fmt.println(angle)
    fmt.println(axis)
}
brianpmaher commented 3 months ago

My current workaround is to wrap angle_axis_from_quaternion in my own function that checks if the value is an identity quaternion and return axis of {0,0,0}.