Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Quaternions 3D

Contributor ,
Apr 08, 2008 Apr 08, 2008
Hello. I'm needing some help with implementing quaternions in ActionScript.

I have been developing a custom 3D engine. I'm familiar with PaperVision 3D (and use it for some projects), yet I also have interest to create a custom (and very streamlined) 3D engine for very specific purposes. I have successfully made a 3D engine using vector math, but am now trying to convert the core rendering process to quaternions (and am getting very confused).

Although I have found pre-made quaternion classes, and read much about quaternion math on-line, I'm still having trouble with getting a solid understanding of quaternions, and for the correct implementation in computation.

Does anyone have a fundamental example of quaternion rotation in use (PaperVision 3D does not seem a good reference for learning how it works).

Here is what I understand (with some questions):

A quaternion represents a four dimensional coordination of x, y, z, and w (or s). The x, y, and z are correlate to the cartesian coordinates of a point, and the w (or s) is a scalar attribute that would be equivalent to spin (or angle). Is this correct? Is w always spin? And is w then always represented as another vector? This is an important fundamental of quaternions that I want to be sure I understand thoroughly.

I have seen this on-line: a quaternion is represented by "q", the scalar by "s", and the position vector by "v":

q = (s, v)

s = cos theta/z

v = u sin theta/z

(u is a "unit vector")

What does all this mean exactly?

First, what is a "unit vector"? Can I assume it is this:

u = [x , y, z]

And if both s and v represent angles, then where is the point? Is one angle an angle of rotation and the other just a angle of placement (for the point)?

So when I create a quaternion as a cartesian point, it is like this:

s = 0;

v = [x, y, z]

q = (s, v)

Then if I want to rotate the point, I understand this (from on-line research):

p = vector point

P = quaternion point (translation)

q = quaternion of rotation adjustment

p = P (0, p);

P = (0, p)

P(rotated) = q P q(-1 or conjugated)

Okay, so how is the quaternion of rotation (q) determined? When I use vector math to calculate 3D rendering and rotation, I can easily rotate a 3D vector with mouse position translated to angel or radian value. When I attempt to do something similar as passing an angle or radian to a new quaternion to represent rotation, I get radical results (a very very fast spin).

The conjugated quaternion is just the negation of the x, y, and z value of the quaternion right? Why is this important in the equation?

TOPICS
ActionScript
891
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 08, 2008 Apr 08, 2008
you have some basic misunderstandings of quaternions. i'd suggest you read some more about them and then return with questions.

in particular, "..A quaternion represents a four dimensional coordination of x, y, z, and w (or s). The x, y, and z are correlate to the cartesian coordinates of a point, and the w (or s) is a scalar attribute that would be equivalent to spin (or angle). Is this correct? Is w always spin? And is w then always represented as another vector? This is an important fundamental of quaternions that I want to be sure I understand thoroughly."

is full of misconceptions.

check wolfram's mathworld. they have solid math info:

http://mathworld.wolfram.com/Quaternion.html

is a reference. read that page and let me know if you have any questions. once you understand that page, you're ready to understand some of the basics.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Apr 09, 2008 Apr 09, 2008
Yes, I had looked at the Wolfram page on quaternions before ... and began to get nauseous!

I will review that page again until I understand (which may take a little time). I am not an expert in mathematics, but I do see a value in understanding quaternions at the most fundamental level.

I had done much research on-line looking at various resources on quaternion mathematics and computation (including the adobe tutorial on 3D quaternions, wikipedia, etc). I recently found this page, which has been the most comprehensive explanation of using quaternions in 3D computation (showing both the math and the computational equivalents):

http://www.gamedev.net/reference/programming/features/quatcam/

Yet, here, right away you can see that even this programmer steers away from:

Q = xi + yj + zk + w

And indulges in the more simplistic:

Q = [ w, v ]

(where v = [x, y, z]) and i, j, and k is never referenced again!

So, I have seen a lot of different representations of applied quaternion math to computational purposes ... different than what is represented in pure mathematics. I'm used to using pure vectors in 3D representation. What is shown above appears to be a compromise between vectors and quaternion math. Ideally, I'm going to want to use quaternions is their purest form in computation. My goal is to master quaternions at ever level! So getting a good understanding of and how to use this will be essential:

Q = xi + yj + zk + w


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Apr 09, 2008 Apr 09, 2008
On first glance at the Wolfram page, it appears that pure quaternion math requires the use of matrices. Is this true? Would this also be required in computation then: that we must us 3D matrices?

As I understood quaternions in a practical sense, one of the primary reasons for using quaternions is that they are supposed to be more conservative (computationally) than matrices (ie., less calculation). So in a quaternion-based 3D engine, would we use matrices or not?


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 09, 2008 Apr 09, 2008
LATEST
no, quaternion operations don't require matrices. it's just one way to represent quaternions.

it's not unusual in mathematics to have more than one way to deal with an object. for example, 2d (or any dimensional) cartesian coordinates and polar coordinates are representations of the same thing: they both allow representations of points (lines, surfaces, hypersurfaces etc) on 2d (or any dimensional surface). but for some operations one is easier to use than the other.

same with quaternions. you can use the representation w+xi+yj+zk or [w,v]. obviously the 2nd representation is shorter and i don't think there's any benefit to using the former representation except to facilitate understanding of the basic quaternion. for all operations, other representations are less messy and easier to understand.

consider multiplication of quarternions using both view points. check how messy it is to multiply quaternions using the first representation compared to the 2nd. neither is particularly attractive, but the later representation is much less messy. (of course, all that mess must be somewhere and in the 2nd representation it's in the dot and cross products).

but it's still easier to manipulate quaternions using the 2nd representation. and there are many other representations of quaternions that may be particularly suited to certain operations.

matrix use is just another way to grapple with an object. while matrix usage can help humans grapple with complex concepts and can help you understand things like 3d rotation (if you understand matrices), they don't help computers because computers don't understand matrices.

computers can be programmed to perform matrix operations, but whether you use matrices in your 3d engine is dependent on whether you understand matrices and they help you understand 3d rotations. hopefully, the answer is yes or you'll have a mess on your hands.

and if it is yes, you'll use your understanding of matrices to program the computer to perform certain operations. but all those operations are going to be regular arithmetic operations whether you convert the matrix operations yourself or you use some prewritten classes that perform matrix operations.

once you understand the wolfram page you should be ready to grapple with 3d rotations and quaternions from:

http://en.wikipedia.org/wiki/Quaternions_and_spatial_rotation
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines