Skip to main content
GameDev.net gamedev.net
🔒 Locked 🎮 Unity

Is there other method than quaternion or rotation matrix to orient animate characters?

Started by pengkuan Jun 1, 2022 at 10:37 PM 34 replies 37.4k views
Original Post
pengkuan
pengkuan

I do not know if there is one. But quaternion and rotation matrix have their drawback. I think they are counterintuitive and complicated slow in computation. So, I propose the following method:

Computing orientation with complex multiplication but without trigonometric function

Today’s methods for computing orientation are quaternion and rotation matrix. However, their efficiencies are tarnished by the complexity of the rotation matrix and the counterintuitivity of quaternion. A better method is presented here. It uses complex multiplication for rotating vectors in 3D space and can compute orientation without angle and trigonometric functions, which is simple, intuitive and fast.

See the article with figures and equations here

https://www.academia.edu/80277267/Computing_orientation_with_complex_multiplication_but_without_trigonometric_function

1. Basic orientation

A rigid body can rotate around 3 orthogonal axes in space, see Figure 1. The state of these 3 rotations is the orientation of this body. The commonly used orientation systems are Euler angles and Tait–Bryan angles[1]. Two methods are usually used to compute orientation: quaternion [2] and rotation matrix [3]. But they have their drawbacks. For quaternion, the computation for rotating a vector p needs to multiply p on the left by the rotation vector q and on the right by its conjugate q-1, which implies two 4D multiplications with p in between, see equation (1). The weird thing is that the rotation vector q is not computed with the rotation angle  but its half /2, see (2), [4]. The half angle and the “sandwich multiplication” make the quaternion method counterintuitive.

For rotation matrix, the 3 angles of orientation are mingled in the 9 elements of the matrix where one gets easily lost. For example, in «Step by step rotation in normal and high dimensional space and meaning of quaternion»[5], the transformation matrix is equation (3) which is confusing with the messed trigonometric functions.

Can we find a better method? In fact, I have constructed a 3D complex number system in «Extending complex number to spaces with 3, 4 or any number of dimensions» [6] which computes easily the rotation of a vector in 3D space. The combination of this system with the step by step rotation described in «Step by step rotation in normal and high dimensional space and meaning of quaternion»[5] gives birth to a new method. This method can use directly the coordinates of points to rotate an object without using trigonometric function. We will explain first this method that uses complex multiplication and trigonometric function.

2. Rotation using complex multiplication

a. Mixed multiplication

We notice that when a 3D vector rotates around an axis that is perpendicular to it, the vector rotates in a plane and we call it the rotation plane. For using 2D complex multiplication in 3D space, we consider the rotation plane as a complex plane and use the 2D complex multiplication to rotate a vector in this plane.

Let (e1, e2) be a plane in 3D space, e1 and e2 the base vectors of the plane, so they 3D vectors. We make this plane equivalent to the complex plane using equation (7), that is, e1 corresponds to the real axis and e2 to the imaginary axis. u is a vector in the plane and is expressed in (8), with a and b being its components. Because the plane (e1, e2) is equivalent to the complex plane, u has an equivalent complex number u, which is expressed in (9). Let v be an other complex number which is expressed in (10).

We multiply u with v and the complex product uv is given in (11). The real and imaginary parts of uv are written in (12). Because the complex plane is equivalent to the plane (e1, e2), we replace the 1 and i that are in (11) with e1 and e2 and obtain uv in (13) which is a vector in the plane (e1, e2).

So, we have created a new type of multiplication: the vector u multiplied by the complex number v. The vector u is a 3D vector because e1 and e2 are 3D vectors. The product of this multiplication is uv which is a 3D vector too. We call this multiplication “mixed multiplication” and the product “mixed product”. We state the Definition 1.

Definition 1: Mixed multiplication and mixed product

The plane (e1, e2) is equivalent to the complex plane. u is a vector in this plane and equals ae1+be2. u is a complex number and equals a+bi. v is an other complex number. u is multiplied by v and the result of this multiplication is denoted as uv and equals real(uv)e1+ imag (uv)e2, with real(uv) and imag (uv) being the real and imaginary parts of the complex product uv. uv is a vector in the plane (e1, e2). This multiplication is called the mixed multiplication and uv the mixed product.

Let us use the newly defined mixed multiplication to rotate the vector u given in (14). The complex number u given in (4) is the complex equivalent of u and the complex number v is the ei given in (5). The complex product uv is computed in (6). Then the mixed product uv is given in (15) whose components equal the real and imaginary parts in (6). So, uv is well the vector u rotated by the angle . We see that mixed multiplication is a very easy way to compute the rotation of a 3D vector in the rotation plane.

See the article with figures and equations here

1. https://www.academia.edu/80277267/Computing_orientation_with_complex_multiplication_but_without_trigonometric_function

2. https://pengkuanonmaths.blogspot.com/2022/05/computing-orientation-with-complex.html

If you wish to download but cannot do from Academia, please click the second link in which please click the black button on the top-right corner of the view window to download

1. Basic orientation 1

2. Rotation using complex multiplication 1

a. Complex multiplication 1

b. Mixed multiplication 2

3. Reference frames 2

a. Ground frame and proper frame 2

b. Direction frame 3

4. Base vectors of the direction frame 3

a. Rotation around the z axis 3

b. Rotation around the y axis 3

c. The 3 axes of the direction frame 4

d. Direction frame and 3d complex number 4

5. Roll, Pitch and Yaw 4

a. Roll 4

b. Pitch and Yaw 4

6. Determination of the angles 5

a. Direction angles 5

b. Roll angle 5

c. Direction frame angles without trigonometric functions 5

d. Roll angle without trigonometric functions 6

7. Computation for oriented points 6

a. Position of one point 6

b. Computation without trigonometric functions 6

c. Procedure of computation without trigonometric function 7

8. Discussion 7

hplus0603
hplus0603

“Extending complex numbers to the 3D space” is literally what quaternions are. (You end up with 4 values, normalized, because Math.) And, if you count number of multiplies and additions, multiplying a vector by a matrix is the minimum possible numeric operations you can do while still having a linearly independent rotation.

Anyway – what you should post is an analysis of the number of multiplications and additions needed for your method, compared to vector-matrix multiplication, and quaternion multiplication. This will work very well to convince people whether it's worth their time to download/access your PDF file and try to read through it, or not.

Now, your claim that matrices make you “easy to get lost” seems like an interpretation problem, not a mathematical problem. Personally, I quite like it that I can just read the three basis vectors right out, and know exactly how my object will be rotated when I rotate it by that matrix. It's really hard to think of anything simper. Other rotational representations, such as the ones you suggest (Tait-Bryant, Heading-pitch-roll, XYX, etc,) and presumably the ones you propose in your paper, may also be helpful, depending on what particular frame of reference you're using, or which particular use case you have (navigating an airplane is different from animating a character is different from physically simulating a rigid body,) but given the strength of conventions already established, the burden of “this is actually easier” is pretty high.

enum Bool { True, False, FileNotFound };
JoeJ
JoeJ

After reading the paper a bit, not going into details, i think your idea could be described this way:

A rotation in 3D can be reduced to a 2D rotation around the axis of rotation.
To do so, we project the 3D vector to the plane of rotation axis, then use complex numbers to rotate the projected 2D vector, after that add the axis times signed distance from the plane to get back to 3D.

Do get this correctly? I'm more assuming. The paper is a bit confusing to me, as it's hard to describe this with words and 2D images. Would be interesting if you could post some minimal code representing your idea.
If my assumptions are right, then there would be nothing new or different about your method, but i may just miss it.

Would your method allow to solve some open problems, e.g. calculating a weighted average of N rotations?

JoeJ
JoeJ

hplus0603 said:
Now, your claim that matrices make you “easy to get lost” seems like an interpretation problem, not a mathematical problem.

The same issue with the claim of quaternions using half angles to be counter intuitive.
If we want to rotate a point 60 degrees, we can reflect it by the line at 30 degrees to get there. (Saw such example in some paper trying the demystify quaternions.)

It's probably no good idea to use such subjective impressions as arguments in your paper.
Proper arguments would be ‘storage of 6 (if so) vs. 9 matrix numbers’, or less operations to rotate a point (if so).

Also, i think you want to elaborate on a data structure from the start. Currently you talk about a method initially, but not so much about the required data structure.

pengkuan
pengkuan

@JoeJ

JoeJ said:

After reading the paper a bit, not going into details, i think your idea could be described this way:

A rotation in 3D can be reduced to a 2D rotation around the axis of rotation.
To do so, we project the 3D vector to the plane of rotation axis, then use complex numbers to rotate the projected 2D vector, after that add the axis times signed distance from the plane to get back to 3D.

Would your method allow to solve some open problems, e.g. calculating a weighted average of N rotations?

In fact, it is not the position vector of a point of the object that I rotate, but the proper frame of the object. For example, the proper frame of a man. Let us see the man as a cross with the vertical beam as his z axis from feet to head, the body axis, and his horizontal y axis is the straight line from his left to right hand while he open his arms to the horizontal. The x axis is in front of his chest.

My solution is to rotate the cross. First, we rotate the cross around the z axis, that is, the body axis. The arms rotate in the horizontal plane. Then, the unit vectors along the x axis and that of the y axis (the arms), are computed with complex multiplication.

Then, the z axis and y axis, that is, the body axis and the chest axis, are rotated in the vertical plane, which also, can be computed with complex multiplication. At this state, the body cross is in the desired orientation. Then, all the points of the man can be positioned in the ground frame by using the unit vectors in the x, y and z direction. This is a transformation of coordinates from the proper frame to the ground frame like with rotation matrix, but without building the matrix.

So, it is not a rotation of one position vector of the man at a time, but the rotation of his frame, then all his points are positioned in the ground frame. It is not the projection of a vector that is rotated, but the base vectors of the frame that are rotated. The base vectors are always perpendicular to the axis of rotation, so we can always use complex multiplication to rotate them and the orientation computation is simplified.

pengkuan
pengkuan

JoeJ said:

hplus0603 said:
Now, your claim that matrices make you “easy to get lost” seems like an interpretation problem, not a mathematical problem.

The same issue with the claim of quaternions using half angles to be counter intuitive.
If we want to rotate a point 60 degrees, we can reflect it by the line at 30 degrees to get there. (Saw such example in some paper trying the demystify quaternions.)

It's probably no good idea to use such subjective impressions as arguments in your paper.
Proper arguments would be ‘storage of 6 (if so) vs. 9 matrix numbers’, or less operations to rotate a point (if so).

Also, i think you want to elaborate on a data structure from the start. Currently you talk about a method initially, but not so much about the required data structure.

The argument with quaternion was just for noting what is the advantage of my method, which justifies that it deserves to be introduced.

I think one of the good arguments in my paper is that one can use complex function which x and y at once using builtin function, which reduces the number of line of code.

As for storage, I have indeed 6 instead of 9, because I define the orientation with the number a, b, d, f, g and h while matrix needs 9. And thus,

frob
frob

I've got to agree with hplus on this one. The standard matrix form is trivial to read, and has all kinds of good info to easily see the basis vectors, the position, and even a little flag to tell you if it is being used as a vector or a point. Although far less convenient to read the quaternion offers benefits for rotation, constant angular velocity, no gimbal lock, and most critically to our uses, less computation work for many operations.

The general expression is “put up or shut up”, and you made a bold claim in your paper:

An other advantage of this method is that the computation of orientation will be faster when the time consuming trigonometric functions are not used and because the process of computation has fewer steps. This is very beneficial for video games, computer-aided design (CAD) or mathematical graphics plotting.

Put up the code library and the disassembled CPU instructions. Prove to the world that it has even less computation work, or is demonstrably faster than what is used now on graphics cards.

I can't tell from your paper if it's faster or has fewer steps than what is currently used. If you provide detailed code both in C++ form and assembly form, especially one that takes advantage of SIMD operations, it would go a long way to prove your point.

Get your raw assembly, get the actual real-world timings versus industry standard best-of-class libraries. Put them side by side. Then it can be a good discussion.

You get those metrics in place and they prove your claim, then you can be sure your new, faster implementations will be adopted across the world.

pengkuan
pengkuan

@frob

I will shut up with you.

JoeJ
JoeJ

pengkuan said:
Then, all the points of the man can be positioned in the ground frame by using the unit vectors in the x, y and z direction. This is a transformation of coordinates from the proper frame to the ground frame like with rotation matrix, but without building the matrix.

You may not build a matrix, but if you calculate rotated points from 3 basis vector defining a frame, you replicate the exact same math a matrix times vector operation is doing:

vec3 rotated = matrix.row0 * local.x + matrix.row1 * local.y + matrix.row2 * local.z

local is a vec3 defining the point in local space, and the 3 rows of the 3x3 rotation matrix represent the same basis vectors you describe as axis.

The problem is: Your explanation is hard to follow precisely and may be interpreted in other ways you intend, so the general audience (like me), tends to assume: ‘The guy did just reinvent wheels, without noticing those wheels already exist.’
Combined with the other general assumption of ‘If there was a better method to do 3D rotations, we would already know about it for decades / centuries’, and we end up ignoring your method, although - eventually - we should take it more serious.

That's why i propose you show code instead equations and pictures, because this way you can replicate your idea exactly.
Then we can understand without risk of wrong interpretation, and we can compare storage and instructions with other methods to confirm technical advantage.

pengkuan said:
so we can always use complex multiplication to rotate them and the orientation computation is simplified.

Your description sounds you actually perform two rotations in sequence to get the final, desired frame.
Not sure if that's simpler than doing just one. It reminds me of Euler angles, which do a sequence of 3, making them very inefficient.

But the bigger question is: How do we define our desired orientation? What's your input and starting point? Multiple angles, one axis and one angle, something like a target point which we want to point at with one basis vector?

pengkuan said:
As for storage, I have indeed 6 instead of 9, because I define the orientation with the number a, b, d, f, g and h while matrix needs 9. And thus,

Post seems corrupted. I guess you tried to post a link. Forum editor tends to crash and cuts your text. Sadly they never fix this bug. Try to avoid links, or put them at the very end, or eventually in a second post.

The 6 numbers are an argument over storage hungry matrices.
Though, we could store just two rows and get the third from a cross product of them. I would assume your method includes the math of this cross product, so more instructions, but less storage.
Storage wise quaternions are very good with 4 numbers, so we often use them because reading memory is more expensive than doing more math instructions.

If your method gives some new sweet spot, yes we should learn and use it. Just post some code.

pengkuan
pengkuan

@JoeJ

JoeJ said:
That's why i propose you show code instead equations and pictures, because this way you can replicate your idea exactly. Then we can understand without risk of wrong interpretation, and we can compare storage and instructions with other methods to confirm technical advantage.

I’m not in game programming and I do not know code. So, I cannot provide code to show the thing. But I think that if in mathematics, we have fewer operations, in computing we will consume less time. So, I provide you with the formulae that show that there are fewer mathematical operations for computing rotation with my method.

Let me explain the joined image of formulae. When computing using trigonometric function, we have to compute cosine and sine for the N+1 thetas.

When computing the complex number way, we start with the complex number z0 and the multiplicative increment zd. The complex product z0*zd=z1 is the complex number of the angle theta1. Then we multiply z1*zd and obtain z2… This chain multiplication is done until N.

As complex multiplication is less time consuming than trigonometric function, the computation of complex multiplication for cosine and sine for the N+1 thetas will use less time than with trigonometric function. Since we have 3 angles to compute, we save 3 times the same amount of time.

Edgar Malinovsky has shown that multiplication wins against trigonometric function. He computed using multiplication instead of trigonometric function to generate 3D fractals objects. He noticed a real acceleration of computation speed. The images of these objects are here as proof.

https://pengkuanonmaths.blogspot.com/2022/04/rendering-of-3d-mandelbrot-lambda-and.html

JoeJ said:
Your description sounds you actually perform two rotations in sequence to get the final, desired frame. Not sure if that's simpler than doing just one. It reminds me of Euler angles, which do a sequence of 3, making them very inefficient.

I have forgotten to mention the rotation around the chest axis. This will make 3 rotations. But, the rotations around the head axis, arms axis and chest axis are more intuitive then Euler's rotations.

JoeJ said:
Post seems corrupted. I guess you tried to post a link. Forum editor tends to crash and cuts your text. Sadly they never fix this bug. Try to avoid links, or put them at the very end, or eventually in a second post.

Thanks for signaling this to me. Have corrected the top post. But I put the links here anyway

1. https://www.academia.edu/80277267/Computing_orientation_with_complex_multiplication_but_without_trigonometric_function

2. https://pengkuanonmaths.blogspot.com/2022/05/computing-orientation-with-complex.html

JoeJ said:
Storage wise quaternions are very good with 4 numbers, so we often use them because reading memory is more expensive than doing more math instructions.

This is also an argument for complex multiplication because real and imaginary parts of a complex numbers are stored together. Fetching one complex number is less expensive than Fetching 2 real numbers. Complex number multiplication is surely more optimised than multiplication of 2 2D vectors.

frob
frob

pengkuan said:

@frob

I will shut up with you.

To be clear, I wasn't saying you need to shut up, I was saying you need to prove your case. That's the only way a paper like that matters.

You made a bold claim that it is faster. That's your claim to prove, and your paper doesn't bear that out.

You need to show it side by side with actual metrics. Compare it against common implementations like DirectX Math, against the Intel Performance Primitives, against NVidia's CUTLASS library. Because unless you have numbers actually demonstrating it is faster than the other major implementations for the operations you're looking at, it doesn't show anything.

Before you have metrics it won't be taken seriously by anyone. After you have metrics everyone may take notice.

JoeJ
JoeJ

frob said:
Before you have metrics it won't be taken seriously by anyone. After you have metrics everyone may take notice.

What if he has no options to create such metrics?

At the moment, he's just sharing an idea. The bold claims may be made out of personal conviction, and now he may be baffled about our requests of proofing the shit out of his stuff, before we even look at it.
I can relate, if i remember what they have done to me, after registering at beyond3D and claiming GCN was 5 times faster than Kepler GPUs with Compute.
I've learned some guys take some things very serious, and request proofs about claims. And that's fine. But to me, initially, the reaction was totally unexpected. I was too naive to expect the obvious.

Imo, doing the metrics could be our job. If we have code, we can implement, optimize, compare it against our established libraries. But that's not yet important.

Likely we just need to read the code to judge performance, but also how it works and if it is useful. Which problems it solves, better or worse, or not.

Maybe i could figure out such code from spending a lot of time on the paper. But i do not really expect to learn something new about 3D rotations, so i'm not willing to spend this time.
And i think this is true for most people, and that's is the major problem some given code would solve: Showing the method clearly, so we know what to talk about.

hplus0603
hplus0603

pengkuan said:
one can use complex function which x and y at once using builtin function, which reduces the number of line of code

Does your argument reduce to “if complex multiplication is as cheap as scalar multiplication, then getting u and v out of a single multiplication is cheaper?"

That is a trivial observation, but it is also based on a false premise. Complex multiplication is no different from a matrix-based 2-matrix multiplication.

Rotating “the cross of the man" is no different from re-calculating the basis, and you still need to re-apply that basis when you actually want to render (or otherwise compute) with the vertices.

And “using a built in function to reduce lines of code” is a totally vacuous claim. You can make any operation “built in” with a single #include directive.

So, my evaluation of this has gone from “might be worth my time studying in detail if you can show some real results,” to “this is not actually new, it's just adding additional operations compared to normal math libraries and will thus run slower, while being less intuitive than reading the basis vectors directly from a matrix, or reading the axis/angle formulation of a quaternion.”

enum Bool { True, False, FileNotFound };
JoeJ
JoeJ

pengkuan said:
I’m not in game programming and I do not know code. So, I cannot provide code to show the thing. But I think that if in mathematics, we have fewer operations, in computing we will consume less time. So, I provide you with the formulae that show that there are fewer mathematical operations for computing rotation with my method.

Oh, i have missed this post yesterday with my former response, which was based on assumption you would be no programmer, eventually.
Fewer operations means less time in general, yes.

pengkuan said:
Let me explain the joined image of formulae. When computing using trigonometric function, we have to compute cosine and sine for the N+1 thetas.

I think you get this wrong. Figure one shows how to construct a rotation matrix from given Euler angles. But this does NOT mean we commonly use trig operations in combination with matrices, or rotations in general.
It is totally common to construct the basis vectors geometrically, avoiding expensive trig ops. One example is how to construct a ‘look at’ matrix, which seems to be the same (or a very similar) idea you propose in your paper.
If somebody has Euler angles data (which usually comes from human interface input, e.g. one animation curve for each angle), then there is no way around of using trig to convert this data into 3x3 matrix, quaternion, or even your custom 6 number representation of a rotation, i'm sure of.

But we don't do this at runtime. Instead we convert Euler angles and key frames e.g. into a sequence of quaternions as a preprocess, and that's the animation data we ship with our games. No more trig is needed when working with this final data.
What we do at runtime with rotations is mainly two things: 1. Rotate lots of points (e.g. vertices of a character) 2. Rotate orientations (e.g. upper leg frame also rotates lower leg and foot bones)
None of those tasks require trig, no matter if we use matrices or quaternions.
We also avoid trig in our runtime simulations, e.g. rigid body physics, ragdoll physics, vehicles, etc.

pengkuan said:
Edgar Malinovsky has shown that multiplication wins against trigonometric function. He computed using multiplication instead of trigonometric function to generate 3D fractals objects. He noticed a real acceleration of computation speed. The images of these objects are here as proof.

Ofc. avoiding trig is a huge win. But to say it clearly: Only beginners use trig in cases it could be avoided, if performance matters.
Early in your paper you propose the concept of ‘Mixed multiplications and mixed product’. To be honest, it almost looks like you have figured out something, and then you think it's a new invention?
It's not new. We all know and use this concept for ages. Some people see such concept as an application of trigonometry (while still avoiding expensive trig ops), others see it as a application of 2x2 matrix math, others see it a s application of complex numbers.
Does not matter, because the math is the exact same no matter how we call it. It also is trivial and obvious, which makes your attempt of presenting this as innovation looking a bit naive. It's fine to explain those trivial things, but giving them new names and presenting them as something new makes no good impression, imo.

pengkuan said:
I have forgotten to mention the rotation around the chest axis. This will make 3 rotations. But, the rotations around the head axis, arms axis and chest axis are more intuitive then Euler's rotations.

Call it x,y,z, or pitch, yaw, roll, or up, left right, or body, chest, stretched arms. The problem remains the same: We need a convention to perform those 3 rotations in specified order, thus we may need conversations between all conventions, and we perform 3 rotations instead just one.

I think it's easy to answer what is the most intuitive, regarding 3D rotations:

If we imagine orientation, we think about the cross visualizing the xyz axis. Because matrices contain those axis directly, matrices are the most intuitive way to represent orientation.

If we imagine rotation, we better avoid the hassle of dealing with multiple rotations in sequence, which gave us all those ‘gimbal lock problems’, coming from people failing to understand this concept in detail.
The easy way is to think of it as a single rotation around a given axis by a given angle. But given axis and angle, we can not work efficiently. So we rather prefer quaternions, because they are pretty close to the axis and angle concept.

So what i think is: It helps to differentiate orientation from rotations, just as much as it helps to differentiate points from vectors.

But that just said for the sake of discussion.

pengkuan said:
This is also an argument for complex multiplication because real and imaginary parts of a complex numbers are stored together. Fetching one complex number is less expensive than Fetching 2 real numbers. Complex number multiplication is surely more optimised than multiplication of 2 2D vectors.

The numbers in a matrix or quaternion are also stored in sequence, so that's no real argument for your method either. It's also just a technical low level detail, not really relevant when looking at the math.

Ok, that's quite some critique from all of us here, but you have to expect this after making claims of a new and better way to deal with 3D rotations.
I think you underestimated our experience on the subject of 3D rotations. What seems new ideas to you is daily practice to us.
Adding this to list of things you should eventually refine on the paper ; )

What's left is to look at your way to rotate a point, and how using 6 numbers affects the necessary instructions to do so.
Maybe i'll look it it in more detail later the day…

JoeJ
JoeJ

JoeJ said:
Maybe i'll look it it in more detail later the day…

Almost there… What i saw so far:

First you reinvent the conversation of Euler angles to basis vectors.
Same thing you criticize about matrices, yielding the same math and amount of trig ops.
(Btw, i do not accept your ‘complex numbers in N dimensions’ concept here either. You perform two 2D rotations in order, and deal with more numbers than 2, but this does not give us new algebra like quaternions, octonions, etc. did. Beside Euler angles conversations, we can see this same math in conversation from cartesian to spherical coordinates, for example. Though, i'm no mathematician and should / can not judge this.)

After that you propose an alternative using points to target at instead angles. So yes, you did reinvent construction of a look at transform.
Though, i think your way of getting there is not as intuitive as the look at. Some code to show typical construction as we are used to:

vec3 xAxis = normalize(targetPoint - objectCenter); // make unit vector pointing towards the target point
vec3 yAxis = normalize(upVector - xAxis * dot(xAxis, upVector)); // project a given upwards direction (to define roll, regarding your example) to the plane of xAxis to make it perpendicular
vec3 zAxis = cross(xAxis, yAxis); // cross product of two axis gives as the third

You should be able to read this. It really is as simple and intuitive as it can get. No need for angles or trig at all.

However, this is just one way of constructing orientation geometrically. It has nothing to do with rotations yet.

Will read the final part about rotating points later…

fleabay
fleabay

I bookmarked this a while back but I have not watched it. Seems like people that are all about math should know about it already but I don't see any references to it in the thread.

🙂🙂🙂🙂🙂<←The tone posse, ready for action.
raigan
raigan

@fleabay lol I was logging in just to share the same thing : ) https://marctenbosch.com/quaternions/​

(for anyone else reading this, definitely check out the paper since it provides example source and analysis of the different methods (IIRC))

JoeJ
JoeJ

Wow. I have this bivectors, wedge products and stuff on my to-learn-list for years, but never got at it.
At some point, i tried to understand quaternions geometrically. And it worked for vector rotation, but trying the same for quaternion multiplication… i made some progress, but it was no success : )

Now i'm old and have accepted the black box. But it feels like coming back to all this might be worth it…

pengkuan
pengkuan

@JoeJ

First, I want to say that I have learned a lot from your posts and you are so kind. Thank you very much.

JoeJ said:
But we don't do this at runtime. Instead we convert Euler angles and key frames e.g. into a sequence of quaternions as a preprocess, and that's the animation data we ship with our games. No more trig is needed when working with this final data.

I did not know this. I came from sciences and in mathematics and physics they do lot of trigonometry. So, in Video Game you are not hindered by trigonometry. You have explained well about mixed multiplication, rotation. So, I let these things down .

JoeJ said:
What we do at runtime with rotations is mainly two things: 1. Rotate lots of points (e.g. vertices of a character) 2. Rotate orientations (e.g. upper leg frame also rotates lower leg and foot bones)

JoeJ said:
What's left is to look at your way to rotate a point, and how using 6 numbers affects the necessary instructions to do so.

When you rotate points at runtime, do you use quaternion multiplication like q*p*q^-1?

With the direction frame of my orientation system, I can rotate a point this way: new point= old point * [B], with B being a 3x3 matrix. I have put the formula in the joined image.

Let me explain the formulae.

Equation 10 is the vector around which we want to rotate a point. This vector is u.

In my system, I call it dx and express it with 4 numbers: a,b,d,f, which are cos and sin of the angles, I have put the expression of dx and a,b,d,f in the equation 11.

Let the point to be rotated be Xg=(xg,yg,zg)

The new point after the rotation is X1g=(x1g,y1g,z1g).

The new point is computed using equation 12, where the first matrix is the inverse of the last matrix. It happens that the inverse of the last matrix is its transpose. In the middle is the matrix of the rotation angle.

The three matrices are multiplied together and make the global rotation matrix [B] in the equation 13.

This way, the rotation of a point is done with the multiplication of the point by the matrix [B] in the equation 14.

I have put the rotation formula using quaternion in 14 for comparison.

My rotation system eq.13 uses 9 multiplications for rotating the point, with the 3 angles given: 2 direction angles and 1 rotation angle.

Using quaternion, eq. 14, because quaternion has 4 dimensions, for the same condition we need 4x3+4x4=12+16=28 multiplications to rotate the point. 4x3 for the first quaternion multiplication: q(xg,yg,zg), and 4x4 for the last. Quaternion multiplication (a1+a2i+a3j+a4k)(b1+b2i+b3j+b4k) gives 16 elements, which means 16 multiplications.

So, we could save 28-9=19 multiplications per point rotated at runtime.

I should be humble in claiming things here, so this number is for discussion.

pengkuan
pengkuan

JoeJ said:
(Btw, i do not accept your ‘complex numbers in N dimensions’ concept here either. You perform two 2D rotations in order, and deal with more numbers than 2, but this does not give us new algebra like quaternions, octonions, etc. did. Beside Euler angles conversations, we can see this same math in conversation from cartesian to spherical coordinates, for example. Though, i'm no mathematician and should / can not judge this.

3D complex number can be multiplied and divided, but which is not explained in the paper.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.