Skip to content
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

QuatRotation construction using symbolics #248

Open
JinraeKim opened this issue Jan 7, 2023 · 6 comments
Open

QuatRotation construction using symbolics #248

JinraeKim opened this issue Jan 7, 2023 · 6 comments

Comments

@JinraeKim
Copy link

JinraeKim commented Jan 7, 2023

I was trying to use a symbolic to construct a QuatRotation but failed.

Can anyone help me to debug this or is it a limitation of this package?

using Symbolics
using Rotations


julia> @variables q[1:4] = [1.0, 0, 0, 0]
1-element Vector{Symbolics.Arr{Num, 1}}:
 q[1:4]

julia> QuatRotation(q...)
ERROR: MethodError: /(::Quaternions.Quaternion{Num}, ::Num) is ambiguous. Candidates:
  /(a::Number, b::Num) in Symbolics at /home/jinrae/.julia/packages/SymbolicUtils/qulQp/src/methods.jl:71
  /(q::Quaternions.Quaternion, x::Real) in Quaternions at /home/jinrae/.julia/packages/Quaternions/kqEsP/src/Quaternion.jl:123
Possible fix, define
  /(::Quaternions.Quaternion, ::Num)
Stacktrace:
 [1] sign(x::Quaternions.Quaternion{Num})
   @ Base ./number.jl:161
 [2] QuatRotation
   @ ~/.julia/packages/Rotations/VYTDG/src/unitquaternion.jl:22 [inlined]
 [3] QuatRotation
   @ ~/.julia/packages/Rotations/VYTDG/src/unitquaternion.jl:46 [inlined]
 [4] QuatRotation(w::Num, x::Num, y::Num, z::Num, normalize::Bool)
   @ Rotations ~/.julia/packages/Rotations/VYTDG/src/unitquaternion.jl:50
 [5] QuatRotation(w::Num, x::Num, y::Num, z::Num)
   @ Rotations ~/.julia/packages/Rotations/VYTDG/src/unitquaternion.jl:49
 [6] top-level scope
   @ REPL[35]:1
 [7] top-level scope
   @ ~/.julia/packages/Infiltrator/r3Hf5/src/Infiltrator.jl:710
@hyrodium
Copy link
Collaborator

hyrodium commented Jan 7, 2023

The error is due to the normalization in the QuatRotation's constructor. This normalization can be avoided with the second variable.

julia> using Rotations

julia> using Symbolics

julia> @variables q[1:4] = [1.0, 0, 0, 0]
1-element Vector{Symbolics.Arr{Num, 1}}:
 q[1:4]

julia> r = QuatRotation(q..., false)
3×3 QuatRotation{Num} with indices SOneTo(3)×SOneTo(3)(Quaternion{Num}(q[1], q[2], q[3], q[4])):
 q[1]^2 + q[2]^2 - (q[3]^2) - (q[4]^2)                2q[2]*q[3] - 2q[1]*q[4]                2q[1]*q[3] + 2q[2]*q[4]
               2q[2]*q[3] + 2q[1]*q[4]  q[1]^2 + q[3]^2 - (q[2]^2) - (q[4]^2)                2q[3]*q[4] - 2q[1]*q[2]
               2q[2]*q[4] - 2q[1]*q[3]                2q[1]*q[2] + 2q[3]*q[4]  q[1]^2 + q[4]^2 - (q[2]^2) - (q[3]^2)

julia> r^2
3×3 QuatRotation{Num} with indices SOneTo(3)×SOneTo(3)(Quaternion{Num}(q[1]^2 - (q[2]^2) - (q[3]^2) - (q[4]^2), 2q[1]*q[2], 2q[1]*q[3], 2q[1]*q[4])):
 (q[1]^2 - (q[2]^2) - (q[3]^2) - (q[4]^2))^2 + 4(q[1]^2)*(q[2]^2) - 4(q[1]^2)*(q[3]^2) - 4(q[1]^2)*(q[4]^2)                                    4(q[1]^2 - (q[2]^2) - (q[3]^2) - (q[4]^2))*q[1]*q[3] + 8(q[1]^2)*q[2]*q[4]
                                 8(q[1]^2)*q[2]*q[3] + 4(q[1]^2 - (q[2]^2) - (q[3]^2) - (q[4]^2))*q[1]*q[4]                                     8(q[1]^2)*q[3]*q[4] - 4(q[1]^2 - (q[2]^2) - (q[3]^2) - (q[4]^2))*q[1]*q[2]
                                 8(q[1]^2)*q[2]*q[4] - 4(q[1]^2 - (q[2]^2) - (q[3]^2) - (q[4]^2))*q[1]*q[3]     (q[1]^2 - (q[2]^2) - (q[3]^2) - (q[4]^2))^2 + 4(q[1]^2)*(q[4]^2) - 4(q[1]^2)*(q[2]^2) - 4(q[1]^2)*(q[3]^2)

julia> principal_value(r)
ERROR: TypeError: non-boolean (Num) used in boolean context

Some methods (e.g. ^) are supported, but I think most of the methods in Rotations.jl (e.g. principal_value) does not work properly.

@hyrodium
Copy link
Collaborator

hyrodium commented Jan 7, 2023

x-ref: JuliaGeometry/Quaternions.jl#123

@JinraeKim
Copy link
Author

JinraeKim commented Jan 7, 2023

@hyrodium Thanks a lot!
Then, in short, is it not encouraged to use symbolics for this package for now?

@hyrodium
Copy link
Collaborator

hyrodium commented Jan 7, 2023

Then, in short, is it not encouraged to use symbolics for this package for now?

Yes, that's right. If Symbolics.jl had compatibility with Quaternions.jl (JuliaGeometry/Quaternions.jl#123), the original error in this issue will be fixed, but I don't know whether other operations work correctly.

@hyrodium
Copy link
Collaborator

hyrodium commented Jan 7, 2023

I think we have the following three ways to solve this problem:

I'm not familiar with Symbolics.jl, so I think the first and the last choices will be acceptable for now.

@sethaxen
Copy link
Contributor

sethaxen commented Jan 8, 2023

One should test if simply making Symbolics compatible with Quaternions resolves this issue. If so, a cleaner way would be to add Symbolics support with package extensions to Quaternions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants