apple / swift-numerics

Advanced mathematical types and functions for Swift
Apache License 2.0
1.68k stars 145 forks source link

Quaternion Math #35

Open pashabou opened 4 years ago

pashabou commented 4 years ago

Since the Numerics modules cover complex numbers and operations, and you mentioned here (#6) that ShapedArrays are within the scope of the project, would quaternion math and possibly other algebras fall under the scope of Swift Numerics as well?

Use cases include everywhere 3D rotation is used, from games and visualization to simulation and control systems. A well-tested and well-documented implementation would be a big boon for a new math library. Some quick googling shows this is not in the C++ STL or a standard part of NumPy, but it is a standard part of MATLAB and part of Accelerate (maybe better suited as part of an update/rewrite of Accelerate?).

stephentyrone commented 4 years ago

Hi @pashabou -- quaternions are definitely in-scope, this is a reasonable suggestion.

A couple quick notes:

markuswntr commented 4 years ago

Hi @pashabou and @stephentyrone,

I just raised a PR with an implementation sketch for Quaternions. I hope it is okay for both of you that I linked the PR against this issue (altough I did not open it).

While the PR already lists all the implementation details, I would like to mention, that I am really liking the implementation of the Complex type and I tried to align Quaternion as much as I could (I even re-used a lot of the comments - sorry). As both may have similar use cases, I found it reasonable to align them as closly as possible.

I have stripped most of the functionality from my initial implementation sketch down to simply having a PR with only the Quaternion type, relevant properties and its most basic arithmetic. It does not define rotations or vector types. I think it will focus the discussion more on the quaternion definition itself and once we have a consent, to iterate upon it. Though, I intent to provide additional functionality (later).

stephentyrone commented 4 years ago

@markuswntr Thanks!

As a heads-up, I'm a little bit swamped for the next few days, but I'll give your PR a quick skim, then provide more detailed feedback sometime next week.

markuswntr commented 4 years ago

Hi @stephentyrone!

Thanks for the heads-up. There is no hurry. And thank you very much for the feedback you already provided.