
Basic skeletal animation with geometric algebra - atomlib
https://www.jeremyong.com/klein/case_studies/ga_skeletal_animation/
======
ninepoints
I'm the author of Klein and was surprised to see a sudden burst of traffic so
I checked the usual suspects and ended up here :)

My goals for authoring Klein was to provide a library for performing all
manner of geometric operations using the language of Geometric Algebra. The
benefits are that the formulism is exception-free (meaning, for example,
parallel planes have a well-defined line of intersection, that projections to
higher/lower grade entities make sense, etc), and works equally well on
points, lines, and planes. Practitioners coming from robotics/animation will
also find the entirety of the Lie algebra/group inside GA as well for smooth
interpolation, etc.

As a graphics engineer, I found most libraries out there unsuitable because of
performance reasons. We're used to having nicely packed SIMD optimized
quaternions for example. Klein fills this gap and (hopefully) in a manner
where you can use it even if you don't understand the Geometric Algebra
(yet!). Over time, I'd like to round out the documentation to explain the
underlying theory, which I find unreasonably elegant and has shifted my
thinking in the last few years.

Let me know if you have any questions about Klein or geometric algebra!

~~~
throwaway17_17
I saw a post in the last month or so on the front page of HN that linked a
video lecture and a paper/presentation on GA, it’s still sitting in my
watch/read folder unfortunately. So, since you volunteered for questions, I’ll
ask a few:

\- is there a generally accepted, or just personally approved, set of
introductory materials on GA, to get one up to speed? I have a decent
mathematics background, but I have been focusing on other areas recently so I
am a bit rusty.

\- I think your goals for Klein look interesting, and since you are a graphics
engineer, I assume you are aware of the prior art (your comment indicates this
is correct), so, is the main draw of using GA as an implementation theory the
elegance of the underlying math alone, or does the math create a new space for
potential optimization in the graphics space (I am assuming that your mention
of performance penalty in existing implementations is due to a lack of focus
on performance not unsuitability of GA to a performance domain).

~~~
ninepoints
Thanks for the questions.

> re: introductory materials

The 3 links I compiled here
([https://www.jeremyong.com/klein/references/](https://www.jeremyong.com/klein/references/))
I consider an absolute must for starting to consume GA. The book (ref #3) has
one chapter undergoing revision regarding the usefulness of the degenerate
metric for modeling projective geometry. My understanding is the chapter will
be released for free once finished. From this alone, I was able to piece
together enough to write one working implementation of GA that I was able to
use to verify the computations and my understanding. Klein is my third GA
library which I wrote once I was pretty sure I was comfortable with the
formalism. Another great set of resources is anything posted on bivector.net.

> re: question 2

The elegance of the math does help me identify better optimizations in a
number of cases, but in other cases, it makes a whole series of operations
well-defined (for which there was no good analog before). I posted some
examples in another comment, but essentially, quats and dual-quats generally
only work on points, and in a somewhat awkward manner. I can't easily compose
2 rotations, a translation, a dual quat, and a quat, and then expect it to
work on a line for example. In GA, this is ... completely trivial. And because
it all fits nicely in the framework, all the above benefits from the same SIMD
optimizations.

I believe the reason GA was not considered well-suited for production/perf
reasons is twofold. First, prior art focused on GA with arbitrary
dimensionality/metric (results in either increased compilation time, or
reduced performance). Second, there wasn't much overlap between
practicitioners of GA, and graphics/animation engineers on the other side. I
view Klein as "low-hanging fruit" in that sense, and consider myself fortunate
to have come across the theory in the manner I did. I had written it off as
just "an easier to understand Quaternion," but once I realized how much I (and
perhaps some of my colleagues) were missing, I opted to actually try and
productionize GA to "fill the gap" so to speak.

(FYI tried to send this over an hour ago but HN keeps rate limiting me :( )

------
bufferoverflow
How do you write an article on skeletal animation, and have zero examples of
what that skeletal animation looks like?

~~~
ninepoints
Working on them! That said though, the audience of this article was originally
meant to be animation engineers that have already "earned some stripes" and
wanted to see the GA formulation.

~~~
uglycoyote
I'm in the intended audience group then, as a game developer who works on
animation regularly but only has a passing familiarity with geometric algebra.
You could say I am "GA curious". But I'm afraid I didn't get much out of that
article. I had hoped I would get more information about the benefits of using
GA over standard matrix and quaternion methods. Instead, at the first mention
of something GA related (which was motors) it was glossed over, as a hand wavy
"don't worry about this". Later, pages of difficult math (which I skimmed over
trying to find the punch line) were devoted to, if I understood, trying to do
the equivalent of slerp that everyone is familiar with and is easy with
quaternions (though perhaps just as complicated to derive). What I would have
liked to have seen is an article that starts off with some motivation about
what benefit one gets from looking at skeletal animation through this lense,
for example, are there problems that vex people using standard methods which
just don't occur when using GA?

~~~
ninepoints
Thanks for the feedback. You may find
[https://www.jeremyong.com/klein/geometry-
potpourri/](https://www.jeremyong.com/klein/geometry-potpourri/) more
approachable but I admit I don't have finalized material I'm completely
satisfied with showing yet :(

The math is definitely more easy to grok if you've seen/used Lie Algebra/Group
formalisms before so that's another shortcoming, but the main thing GA gives
us here is a "dual-quaternion slerp" which I literally could not find an
implementation of anywhere! The formula for a quaternion slerp is actually not
too hard to derive, but a dual-quaternion slerp is far more difficult. Part of
the point of the post was that this was somewhat surprising to me (both that
GA makes it approachable, and that dual-quaternion slerp implementations
didn't exist in the wild).

~~~
uglycoyote
Thanks! I'm curious what motivated you to want to use a dual quaternion or why
you want a slerp algorithm for that. I have yet to run across a use for a dual
quaternion. Wikipedia says that they are used in mechanics to represent rigid
transformations. That sounds useful for animation but most animation or
computer graphics people would represent a rigid transformations with a
quaternion and a translation vector, and if interpolating a rigid
transformations they would slerp the quat and linearly interpolate the
translation. So I'm not sure what the advantage of a dual quaternion would be
in this context, or do you use dual quaternions in some completely different
way?

~~~
ninepoints
Thanks for the questions. Indeed many animation libraries store the quaternion
and translation as separate components. There are a few reasons I use dual-
quaternions in my own code. First, because I can "slerp" them, this means that
when I compress keyframes, and can perform better quality fits (potentially
less error and fewer keyframes needed). The dual-quaternion has uses in
skinning which I'm sure you're aware of, but if the base transformation is a
dual quaternion, I can more efficiently morph neighboring vertices as well
(I've ported the dual-quaternion application to shader code as well). One
optimization that GA makes clear is the ability to factor out terms when
applying a dual quaternion to a number of entities all at once which makes it
almost as efficient as a quat-translation while conserving energy as well.

Finally, the dual-quat representation is beneficial when modeling kinematic
motion specifically (not necessarily artist-authored) which can be useful in
contexts beyond games (e.g. robotics, deep-learning, computer vision), but
also inverse kinematics (which unfortunately I haven't had time to write about
yet)

------
modeless
Geometric algebra looks cool, and this library seems like exactly what is
needed for graphics programmers to use it.

What I'd really like to see is a comprehensive cheat sheet with formulas for
common tasks in computer graphics with an absolute minimum of theory and
jargon; even less than this article. Of course it's great to learn the theory
too, but most people just call slerp in a quaternion library without learning
the theory of quaternions. It should be possible to use a geometric algebra
library in a similar way.

~~~
ninepoints
Original author here, it is absolutely my goal that the library should be
usable without needing to understand the ins and outs of GA. To this end, I've
started adding a bunch of "helper" functions that do tasks like projecting a
point onto a plane, or identifying the line through a pointer parallel to
another line, etc.

I've been (slowly) working on additional documentation in the meantime and
didn't expect to see the animation article hit the frontpage :). That said, in
the meantime, there is a GREAT cheatsheet for all the relevant formulae here:
[https://bivector.net/tools.html](https://bivector.net/tools.html) (scroll
down to the bottom). You can get the PDF version here:
[https://bivector.net/3DPGA.pdf](https://bivector.net/3DPGA.pdf)

~~~
auggierose
I was wondering, once you've abstracted from the GA bits enough, is there any
point of using GA at all? I like GA as well, just wondering what it gives you
once you've abstracted it away. Or in other words, are there aspects of GA
that cannot be abstracted away like that?

~~~
ninepoints
Yes actually :)

It took me a long time to actually decide to invest in GA because the
sentiment I had was "it just replaces what I already know" and what I knew at
the time was matrices, quaternions, and dual quaternions.

It turns out, I was pretty wrong in that respect. For example, in the current
predominant formulism, it's awkward to rotate a line with a quaternion, then
identify the dual quaternion that maps that line to yet another line, then
apply that dual quaternion to a point. In GA, this just works (mind exploding
gif). Or, I can construct a line between two points, then find the quaternion
that maps a different line to that one, and convert it to a matrix to do "look
at" transforms in a shader. Also just works.

I think the more I use GA, the more elegant I find it, and it takes me well
past the formulism I used to know (which is still useful from time to time,
but far less expressive). While I could provide helpers for all the common
operations, the operators in GA will always have their use because... there's
just so much you can do with it. At some point, the library will just because
unwieldy/large. I haven't necessarily found the sweet spot yet for
size/convenience, but I hope to converge there over time. Provide enough to be
usable for most people, while at the same time being a launchpad for learning
more about the abstraction itself.

From an implementation point of view, I've found a number of optimizations
that were made easier (or even possible) with GA that I hadn't identified
despite working with quaternions for years before.

~~~
auggierose
Ok, thank you, very helpful. So I guess your opinion on this is, if you know
enough GA, then GA becomes the best library you could think of.

~~~
ninepoints
Yup, now that I've "swallowed the red pill" so to speak, I can't even look at
quats/dual-quats in the same way. They are very much a small cross-section of
something much bigger (more expressive/powerful/etc).

------
enkimute
Just a heads up - @ninepoints let me know he got rate limited and will answer
as soon as allowed again ;)

------
duchess_toffee
Ninepoints is getting repeatedly rate-limited. He invites anyone with
questions to ask questions in the Klein discord
([https://discord.gg/gkbfnNy](https://discord.gg/gkbfnNy))

~~~
ninepoints
The mods emailed me a couple hours ago and said my account was mistakenly
flagged as a "spam" account but its been since corrected. Thanks!

