Skip to content

Rethink to_euler_angles #86

@moble

Description

@moble

I'm thinking something like this might give us a nicer treatment of beta:

function to_euler_angles_beta_doubled(q::AbstractQuaternion{T}) where {T}
    w, x, y, z = q[1], q[2], q[3], q[4]

    # α and γ from usual formulas (can be outside [0,2π))
    a₁ = atan(z, w)
    a₂ = atan(-x, y)
    α = a₁ + a₂
    γ = a₁ - a₂

    # β magnitude
    c = hypot(w, z)
    s = hypot(x, y)
    β = 2atan(s, c)  # in [0, π]

    # Decide whether to extend β to > π
    # If the "Hopf" product has negative real part, flip β
    if w*x + z*y < 0
        β = 2T(π) - β
    end

    @SVector [α, β, γ]
end

Probably change to have β ∈ (-π, π] or so. The idea here is to put the weird functional behavior at the same point as the weird geometric behavior — when the rotation is exactly a rotation of the z axis onto the -z axis, and the choices of the ways to get there are exactly all the possible unit vectors in the x-y plane. This should minimize the problems with differentiation by putting the bad place far away.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions