crertel / graphmath

An Elixir library for performing 2D and 3D mathematics.
The Unlicense
79 stars 14 forks source link

Conversion between quatern and rotation matrix wrong? #17

Closed jimsynz closed 6 years ago

jimsynz commented 7 years ago

Unless I'm wrong, converting to a rotation matrix and back should be reversible, right?

iex> Graphmath.Quatern.create(1,2,3,4)
...> |> Graphmath.Quatern.to_rotation_matrix()
...> |> Graphmath.Quatern.from_rotation_matrix()
{2.0, 3.0, 4.0, 1.0}

So it looks like the elements of the quatern tuple are being reversed. Is this a bug?

crertel commented 7 years ago

That may well be a bug--thank you for your observation!

Could you see if this behavior occurs using unit quaternions as well?

jimsynz commented 7 years ago

It looks your hunch is right:

iex> Graphmath.Quatern.create(0.978015, 0.135224, 0.137461, 0.0794041)
...> |> Graphmath.Quatern.to_rotation_matrix()
...> |> Graphmath.Quatern.from_rotation_matrix()
{0.9780153026441815, 0.13522395815530017, 0.13746095746306655,
 0.07940407542861673}
crertel commented 7 years ago

Good to see that that was right!

I'm half-tempted to require enforcement of unit quaternions all along the pipeline, as per some discussion here. Any thoughts?

jimsynz commented 7 years ago

Your call :)

crertel commented 6 years ago

So, for the moment, I'll let this lie. Let me know if you're having any further problems. :)