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

Add Quaternion nodes #2341

Merged
merged 1 commit into from
Dec 31, 2018
Merged

Conversation

DolphinDream
Copy link
Collaborator

@DolphinDream DolphinDream commented Dec 23, 2018

To start with, this adds 3 nodes (quaternion in, quaternion out and quaternion math nodes).

Quaternion In:
Provides conversion to quaternion from various format inputs (selectable via the mode option):

  • components wxyz
  • angle + axis
  • euler angles
  • matrix

Quaternion Out:
Provides various components (conversion) from quaternion to various components:
(w,x,y,z) components, matrix, axis + angle, Euler angle

Quaternion Math:
Provides the essential quaternion arithmetic operations:

ADD
SUB
MULTIPLY
DIVIDE
ROTATE
DOT
DISTANCE
INVERT
NORMALIZE
CONJUGATE
NEGATE
SCALE
MAGNITUDE

Note: some operations take multiple quaternion inputs (input list grows as new sockets are connected), as well as single quaternion inputs, or quaternion + scalar input.

  • Code changes complete.
  • Code documentation complete.
  • Documentation for users complete (or not required, if user never sees these changes).
  • Manual testing done.
  • Unit-tests implemented.
  • Ready for merge.

All three nodes :
sv-quaternionnodes-ui1

Quaternion IN node:
sv-quaternionin-01

Quaternion OUT node:
sv-quaternionout-01

Quaternion MATH node:
sv-quaternionmath-01

@DolphinDream
Copy link
Collaborator Author

DolphinDream commented Dec 23, 2018

As you notice.. I decided to make the Quaternion In node mode based (to switch input formats).. where the input given to the node to convert into a quaternion can have various formats (wxyz components, euler angels, axis+angle and matrix). It can be argued (based on recent conversations) that is preferred to have simpler nodes that do one, simple function, and thus perhaps make 4 “Quaternion In” nodes that generate quaternions based on different inputs. The second school of thought (which i prefer in this case) is to keep the number of nodes to a minimum by making one node with 4 modes (as proposed). If anybody feels strongly about this proposal feel free to comment, brainstorm etc.

@DolphinDream
Copy link
Collaborator Author

DolphinDream commented Dec 23, 2018

For the Quaternion Out node I decided to show all possible components that users may want to get out of a quaternion with all outputs visible. The components are calculated of course only for the connected outputs. An alternative implementation could provide a “mode” similar to the QIN node and have the user select the kind of output they desire to read (Matrix, Components, Axis-Angle, Euler, Magnitude etc). (though perhaps magnitude can be made part of the QMath node a separate function, similar to what the vector math does). With a mode option, the visible output nodes will only the ones corresponding to the selected mode. Personally I don’t see a huge benefit of hiding output socket, but if anybody feels strong against it I can cleanup the output interface by adding a mode. Thoughts ?

@Durman
Copy link
Collaborator

Durman commented Dec 24, 2018

What about using data structure of quatarnions from mathutils library without conversion to list, like we do with matrix now?

@DolphinDream
Copy link
Collaborator Author

DolphinDream commented Dec 24, 2018

What about using data structure of quaternions from mathutils library without conversion to list, like we do with matrix now?

@Durman I was going to ask about it :) it is beneficial to have it as mathutils Quaternions directly and I can certainly remove all the tuple()’s around the output. This would save having to convert back and forth from list to quaternions to do Q operations. The only reason why I didn’t do it was because a Quaternion is closer relative to a Vector than a Matrix (structure wise).. and for vertices we don’t have output as Vector(0,0,0). But to your point, maybe we should have vertices also output mathutils Vector instead of list? If the Stethoscope output becomes too verbose having the extra type displayed (Vector, Quaternion, Matrix etc) then perhaps the Stethoscope node could be smarter about it and have an option to not display the type but only the value.

If nobody objects I’ll switch the output to mathutils Quaternion.

@DolphinDream
Copy link
Collaborator Author

Some updates to all 3 nodes.. updated UI and output is now Quaternion instead of tuples.

sv-quaternionnodes-ui2

@DolphinDream
Copy link
Collaborator Author

An node flow example with connections and outputs..

sv-quaternionnodes-example1

@DolphinDream DolphinDream force-pushed the quaternionNodes branch 2 times, most recently from e3b4527 to 5dfe245 Compare December 24, 2018 22:53
@DolphinDream
Copy link
Collaborator Author

DolphinDream commented Dec 25, 2018

The Quaternion Math ... in all of its glory :) Listing operations grouped in their corresponding input/output configurations (NQ=>Q, QQ=>Q, QQ=>S, Q=>Q, Q=>S and QS=>Q).

sv-quaternionmath-02x

@DolphinDream DolphinDream force-pushed the quaternionNodes branch 5 times, most recently from 51af93f to 39528f9 Compare December 29, 2018 16:15
@DolphinDream
Copy link
Collaborator Author

DolphinDream commented Dec 29, 2018

Here’s the latest UI for Quaternion IN/OUT nodes. I added “mode” to QOUT node as well to cleanup the interface and make it similar to its QIN counterpart. Also now the QOUT node outputs Euler angles as well.

Note: For the angle units in introduced an additional “UNI” mode, which is a 0-1 angle unit (1 = one cycle = 2pi = 360 degree angle). Useful for cases when the input angle is driven by evaluators (e.g. Frame Info node) and avoids having to multiply by 2pi or 360 to get the angle in correct units.

sv-quaternioninout-ui

@DolphinDream
Copy link
Collaborator Author

I removed the Cross operation from QuaternionMath node since it is identical to the Multiplication operation.

Here’s the latest UI and math operation groups.

sv-quaternionmath-ui3

sv-quaternionmath-03

@DolphinDream
Copy link
Collaborator Author

Well.. this PR is pretty much done and ready to be merged. Speak now or forever... :)

- add 3 nodes: Quaternion In, Quaternion Out and Quaternion Math

Quaternion In:
Provides conversion from various quaternion components to quaternions (selectable via the mode option):
- components wxyz
- angle + axis
- euler angles
- matrix

Quaternion Out:
Provides conversion from quaterions to various quaternion components (selectable via the mode option):
- components wxyz
- angle + axis
- euler angles
- matrix

Quaternion Math:
Provides various quaternion arithmetic operations:

ADD
SUB
MULTIPLY
DIVIDE
ROTATE
DOT
DISTANCE
NEGATE
CONJUGATE
INVERT
NORMALIZE
SCALE
MAGNITUDE

Note: some operations take multiple quaternion inputs (input list grows as new sockets are connected), two quaternion inputs, single quaternion inputs, or quaternion + scalar input.
@DolphinDream DolphinDream changed the title Add first Quaternion nodes (WIP) Add first Quaternion nodes Dec 31, 2018
@DolphinDream DolphinDream changed the title Add first Quaternion nodes Add Quaternion nodes Dec 31, 2018
@DolphinDream DolphinDream merged commit 9df2933 into nortikin:master Dec 31, 2018
@nortikin
Copy link
Owner

nortikin commented Jan 16, 2019

ok, updated from github, find out this nodes, searched how to use quaternions, find book on market, bought it. This chain anyway not solving my understanding of quaternions. Also book is more as math history, not math itself. But i see, we can rotate anything anyhow now.
Thanks

@DolphinDream
Copy link
Collaborator Author

@nortikin Sorry for your frustration :) It's not clear yet the real use of these nodes, but I suspect we'll learn as we go and discover if they were as useful as anticipated. What book on quaternions did you get, btw?

Also, note that there is a whole subset of nodes currently missing that are needed to complete the quaternion (4D Vector) domain, such as the 4D Matrices (5x5) which are to operate on 4D vector (quaternions) space the same way as the 3D Matrices (4x4) operate on 3D vector space. Some I already started developing (emerged from the hypercube PR I started a while back) and still need some more developing before I can push them in a PR (the nodes marked with a green bullet). Perhaps once you can operate on 4D space with more power (4D Matrices) the quaternion nodes could become more useful.

In the meantime, of course, since normalized quaternions map to 3D rotation matrices they can definitely be used to do 3D rotations (as well as SLERP in conjunction with the MixInput nodes).

sv-3d-4d-space

@nortikin
Copy link
Owner

this book is Ian Stewart 'calculating the cosmos' and 'professor stewart's cabinet of math curiosities', not quaternions and ordered his 'symmetry' book

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

Successfully merging this pull request may close these issues.

3 participants