Processing math: 100%

neděle 9. června 2013


Multi-parent constraint

Ok what is the deal? For example when you animate foot sometimes you want to rotate it about forefoot and sometimes about hindfoot. Or you want to animate things like this http://www.youtube.com/watch?v=lOfaFJq5Wqk . I have simple solution.

I assume that reader is familiar with quaternions and their aplication to rotation if not than please see http://en.wikipedia.org/wiki/Quaternions_and_spatial_rotation

So let's get mathematical. Beware everything is quaternion(I will try to stay consistent in notaion with wiki page on quaternion, like conjugation is denoted with star)!
ttimep0(t)position of the footq0(t)quaternion which specifies rotation of foot aroundp0now for i>0pi(t)positions of points you want to rotate aroundqi(t)quaterion which specifies rotations around corresponding point

Suppose you know p0,q0,pi at some time t0 and qi(t) for all t>t0. Than you want to find p0(t),q0(t),pi(t). But what should they satisfy??

First denote with vi relative position of pi to the p0 at time t. So:
vi(t)=pi(t)p0(t)
Points pi should stay fixed relative to foot. Therefore they have to satisfy:
pi(t)=p0(t)+R0(t)vi(t0)R0(t)

where Ri(t)=qi(t)q1i(t0) which represents change in rotation from time t0 to time t. .

Now imagine situation when you rotate only about point p1. So pi,qi  for i>1, p1 are constant in time and only q1 changes in time. What do we get? We rotate point p0 around point p1:

p0(t)=p1(t0)R1(t)v1(t0)R1(t)
q0(t)=R1(t)q0(t0)

Now replace p1(t0) with pi(t0)=p0(t0)+vi(t0) we get:

p0(t)p0(t0)=v1(t0)R1(t)v1(t0)R1(t)

So point p0 changes about vi(t0)R1(t)v1(t0)R1(t) thanks to rotation about point p1. We assumed that p1. When p1 varies in time than previous equation is "sort of OK"(it does not represents accurately the rotation of p_0 around point p_1(which varies over time)) only for small times Δt=tt0.

Now suppose that pi,qi all varies in time and Δt is small. Than we can generalize our update equation:

p0(t0+Δt)p0(t0)=ivi(t0)Ri(t0,Δt)vi(t0)Ri(t,Δt)

where R(t,Δt)=qi(t+Δt)q1i(t). But how do we update q0 ?? We could do q0(t+Δt)=R1(t,Δt)Rn(t,Δt)q0(t) But it depends on order of the Ri which is undesirable. So we do better with:
q0(t+Δt)={Ri(t,Δt)}iq0(t)

where{Ri(t,Δt)}is what I call normalized anticommutator defined by:

a1,,an are any quaternions than

{ai}i=σΠnaσ(1)aσ(n)||σΠnaσ(1)aσ(n)||

where Πn is set of all permutations of size n. I think that normalized anticommutator is the most convenient way how to combine n rotations and get again rotation. And quaternions are the good way to do it. Problem with matrices is that when you add two rotational matrices than you hardly get rotation matrix and finding closest rotation matrix to that sum is just pain. With quaternions it is easy, just add them up and normalize.

We are almost finished. We just polish those equations a little bit.

denote tn=t0+nΔt than our update equations looks like this:

vi(tn+1)=pi(tn+1)p0(tn+1)=R0(tn,Δt)vi(tn)R0(t,Δt)p0(tn+1)=p0(tn)+ivi(tn)Ri(tn,Δt)vi(tn)Ri(tn,Δt)q0(tn+1)={Ri(tn,Δt)}iq0(tn)pi(tn)=p0(tn)+R0(t0,tnt0)vi(t0)R0(t0,tnt0)

Horay! finished.

I implemented it to Autodesk Maya. You can download the plugin here:
http://uloz.to/xgp17H2G/multiparent-zip
or
http://www.4shared.com/zip/MqwiOuUt/multiParent_1.html

Watch video how to use it:
http://www.youtube.com/watch?v=5Oip-YiKuik

I hope you like it! If you find any mistakes please let me know ;)

Further investigation:

Send Δt to zero and obtain differential equations from those update equations and analyze their behavior!