Jump to content

vex quaternion dot doesn't behave like expected


sanostol

Recommended Posts

Hi

I'm trying to do a quaternion dot product in vex. for this i fetched 2 transforms from the objectlevel, i use to nulls.

with the optransform(thanks sidefx for fixing it :D ) i get the matrix4, after converting them to matrix3 and quaternion I do the dot product of them

matrix3 $basematrix = optransform($base);
matrix3 $targetmatrix = optransform($target);
$basequat = quaternion($basematrix);
$targetquat = quaternion($targetmatrix);

$dot = $basequat[0]*$targetquat[0] + $basequat[1]*$targetquat[1] + $basequat[2]*$targetquat[2] + $basequat[3]*$targetquat[3];

but somehow the quaternions and the dot do not behave like expected

the base object stands still, rx, ry rz are zero

the targetobject is rotatet around y from -360 to 360, at at the blue bar the roation is 0

here is a motionview of what is going on on the

quaternions of the target null from -360 < ry 360:

targetquat.jpg

and finally the dot product:

dot.jpg

i expected something like - 1 to 1 to -1

with no breaks in it

what's going wrong?

are the quaternions non normalized?

i attached the file

quatprob.zip

Edited by sanostol
Link to comment
Share on other sites

You might find that instead of just extracting the quaternion from the matrix that you are better off transforming a base quaternion identity by the matrix to get the target quaternion.

I can't remember if this is the method I used for my quaternion deformers, I think it is, I'll take a look when I'm back at my machine with it on.

Link to comment
Share on other sites

I think you should read up a bit more on quaternions. There are several misunderstandings about quaternions:

- given the quatenion q, -q and +q represent the same rotation. the discontinuities are expected. the usual way to perform slerp interpolation is to negate one of the quaternions before performing the interpolation if the dot product of the two quaternions is negative in order to ensure a shortest path rotation.

- as a result of these discontinuities, the dot product will also exhibit discontinuities at the same time because of the quaternion flipping

- multiplying quaternions is the cross product of the two 4 dimensional quantities, it is NOT a dot product. if you want to rotate a point, then it's neither a just a cross product nor a dot product, you should look up on how to properly do this.

BTW, you can just multiply two quaternions together in VEX, it will do the right thing (ie. cross product).

Link to comment
Share on other sites

Yes, but take into account the italic print at the top of the article:

... we've come to feel that this article contains misinformation (as many have pointed out) that could prove to be confusing and misleading to the many beginners who turn to us as a source of information
Link to comment
Share on other sites

Yes, but take into account the italic print at the top of the article:

Yup. That's why I'm cautiously labeling it as "interesting read" :)

What do you make of it? Are the objections mere academic nit-picking? Or truly flawed understanding?

I simply don't have the necessary background to form an intelligent opinion; but you do. So waddya think, Ed?

[EDIT] Ooops... guess we posted at the same time. Thanks for the references! [/EDIT]

Link to comment
Share on other sites

I read that article a long time ago and so I don't remember all its problems anymore. As I recall, I skipped over most of the math since it wasn't really anything new so I don't know if her math is correct but it probably is. It's mostly that her arguments against quaternions are very one sided. Take for example,

4. Quaternion operations don't require trig, vector operations do.

A. Don't get too hung up on this. A dot product is a cosine whether you are talking about vectors or quaternions.

But there's a big difference here between computing cos() using the dot product and computing cos() by invoking the CPU instruction.

Ultimately, the article is just a rant against blindly using quaternions as a magic bullet for everything, which I agree since I don't believe in magic bullets. :)

Link to comment
Share on other sites

I think you should read up a bit more on quaternions. There are several misunderstandings about quaternions:

- given the quatenion q, -q and +q represent the same rotation. the discontinuities are expected. the usual way to perform slerp interpolation is to negate one of the quaternions before performing the interpolation if the dot product of the two quaternions is negative in order to ensure a shortest path rotation.

- as a result of these discontinuities, the dot product will also exhibit discontinuities at the same time because of the quaternion flipping

- multiplying quaternions is the cross product of the two 4 dimensional quantities, it is NOT a dot product. if you want to rotate a point, then it's neither a just a cross product nor a dot product, you should look up on how to properly do this.

BTW, you can just multiply two quaternions together in VEX, it will do the right thing (ie. cross product).

Hi Edward,

in this case I want the dot product, and I don't want the shortest path for rotation. I'm doing my own slerp, and for this i need the sign. Consider a long neck that spins around 180 degree and then decides for the shortes path. I did a operator for spines and stuff like that in another software this way, and it is able to spin around in every direction up 360 degrees this way,without flipping at 180. so I really want this sign :)

Thanks for the links, I guess You can never read to much about stuff like that

Edited by sanostol
Link to comment
Share on other sites

Thanks Sibarrick

but how can I transform a quaternion with a rotation matrix, other than that I have to convert the matrix to a quaternion to multiply. could not find a vex function for this

Seems I mis-remembered, been a long time since I looked at this. I also use the same method you have but I've never had the flipping issue, probably because I've always required the shortest path blending.

I'm sure I have come across a solution to this somewhere though, racking my brain now to think of where....

Link to comment
Share on other sites

  • 4 weeks later...

Calculon is still thinking :rolleyes:

I thing I understood the problem and the possible solution. it lies in the nature of the matrix to quaternion conversion. i did it manualy (inlinecode) and it is the sqrt function that makes it impossible to keep the sign. not a problem if You need the shortes path. but in my case I found that the euler to matrix conversion does the trick. continuous quaternions, yeah.

what a wonderfull (houdini)world :)

does anybody know how to collect all quaternions of all parentobjects easily by converting their eulers to quaternions in houdini recursivly.

Seems I mis-remembered, been a long time since I looked at this. I also use the same method you have but I've never had the flipping issue, probably because I've always required the shortest path blending.

I'm sure I have come across a solution to this somewhere though, racking my brain now to think of where....

Edited by sanostol
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...