I’m working with 3D rotations, and my current code implements rotation matrices from Euler angles.
I would like to switch to a more general approach that leverages Rotations.jl (or ReferenceFrameRotations.jl
, but that’s a separate discussion). I like the idea of abstracting away the specific convention that the user may prefer (parametrising with Euler angles, or axis-angle, or quaternions, etc.) but I haven’t been able to adapt my code to work with the supertype common to them all. Here’s what I mean:
using StaticArrays
# current definition: each object is given 3 Euler angles to describe the rotation
struct current_clust{T}
angles::Vector{SVector{3,T}}
end
current_clust(SVector.(1:4,2,3))
# current_clust{Int64}(SVector{3, Int64}[[1, 2, 3], [2, 2, 3], [3, 2, 3], [4, 2, 3]])
vs my attempt at a new approach:
using Rotations
# new implementation: each object would be assigned a generic "Rotation" object
struct new_clust{T}
angles::Vector{Rotation{3,T}}
end
r = rand(RotMatrix{3})
q = UnitQuaternion(r)
e = RotXYZ(0,1,2)
aa = AngleAxis(r)
new_clust([r, q, e, aa])
# ERROR: DimensionMismatch("No precise constructor for Rotation{3, Float64} found. Length of input was 9.")
Is my idea flawed (e.g. would the new_clust
objects be inefficient because of arbitrary types)? Or do I just have the syntax wrong? (e.g I need a different container)?
I don’t really know how to probe the different subtypes – from what is printed they all seem “compatible”, as in
supertype(typeof(r))
Rotation{3, Float64}
etc.
giving me the impression that I could just group them together in a vector. But at the same time I expect that internally they’re stored quite differently (e.g. 3, 4, or maybe 9 elements, etc.). How can I check this kind of thing?
Of course I could coerce everything into 3x3 matrices, but that would seem a bit wasteful.