Archived

This topic is now archived and is closed to further replies.

Inspect a paper on 4D rotation, anyone ?

This topic is 5774 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Heya everybody- I`ve just gotten done writing about 4D rotation. But, before I put it on my website, I want to make sure everything is accurate. So... Take a read, please. ---------------------- Rotation in 4 Spatial Dimensions. Paul "V''lion" Nathan. So you have decided to make a 4D engine, have you ? Good for you ! I`m going to discuss 4D rotation, extrapolating the 4D equations from the 3D equations, as well as using 2D rotation for various purposes. I`m not going to go into the actual mathematical proof for rotation; thats well documented on the internet in 2D and 3D contexts and it does not change for 4D. Lets start by rotations in the plane- Call it the XY plane, and we will be using 2-space. I will use C++ code. math equations for 2D are: x'' = y * sin(theta) + x * cos(theta) y'' = y * sin(theta) - y * cos(theta) code. void c2DPoint::2DRotate(float theta) { float x0, y0; x0 = y * sin(theta) + x * cos(theta) y0 = y * sin(theta) - y * cos(theta) //This just assigns the results to itself, assuming c2DPoint has a x and a y. *this.x = x0; *this.y = y0; } Now, you are wondering, why just not use x and y, instead of x0 and y0 ? Because if you did, you would screw up the equation. It needs the original, unaltered x and y to operate with. So it requires 1 angle and 1 equation set to do a 2-space rotation. Lets go into the 3-space rotation. The maths hairly, but don`t let it confuse you ! Just remember that y'' is simply a different variable than y. x'' = y * sin(theta) + x * cos(theta) y'' = y * sin(theta) - y * cos(theta) z'' = z x'''' = x'' * sin(phi) + x'' * cos(phi) y'''' = y'' z'''' = z'' * sin(phi) - z'' * cos(phi) x'''''' = x'''' y'''''' = y'' * sin(chi) + y'' * cos(chi) z'''''' = z'' * sin(chi) - z'' * cos(chi) Heres the code; void c3DPoint::Rotate(float theta = 0, float phi = 0, float chi = 0) { c3DPoint temp0, temp1, temp2, temp3; temp0 = temp1 = temp2 = *this; //XY plane temp1.x = temp0.y * sin(theta) + temp0.x * cos(theta); temp1.y = temp0.y * cos(theta) - temp0.x * sin(theta); temp1.z = temp0.z; //XZ plane temp2.x = temp1.z * sin(phi) + temp1.x * cos(phi); temp2.y = temp1.y; temp2.z = temp1.z * cos(phi) - temp1.x * sin(phi); //YZ temp3.x = temp2.x; temp3.y = temp2.z * cos(chi) + temp2.y * sin(chi); temp3.z = temp2.z * cos(chi) - temp2.y * sin(chi); *this = temp3; } We now have 3 angles, and 3 equation sets. I won`t do the math for 4 dimensions, but it works _exactly_ as does the 2D math and the 3D math. What that means for you is you have to do- heres the funky part- 6 sets of equations, and 6 angles. That really shocked me when I found it out- I just didn`t believe it. But, heres how it works. In 2D, the plane is XY. All angles are expressed from a initial and a terminal side in the plane. In 3D, we have 1 more axis. But- 2 more planes: YZ and XZ. So in 4d, we have 4 axes, and 3 more planes. XQ, YQ, and ZQ. Add all the planes up and you get 6 planes, with 4 axes. If you have 1 rotation a plane, that means- 6 angles. Here is the relevant code from my own engine, bugle4d: //Works similar to the OGL function, but operates against the point that calls it. //6 angles. XY plane, XZ plane, YZ plane, XQ plane, YQ plane, ZQ plane. void c4Point::Rotate(float theta = 0, float phi = 0, float chi = 0, float rho = 0, float mu = 0, float lambda = 0) { //I know I could use like only 3 of these, but having all of these makes it more clear c4Point temp0, temp1, temp2, temp3, temp4, temp5, temp6; temp0 = *this; //XY plane temp1.x = (temp0.y * sin(theta)) + (temp0.x * cos(theta)); temp1.y = (temp0.y * cos(theta)) - (temp0.x * sin(theta)); temp1.z = temp0.z; temp1.q = temp0.q; //XZ plane temp2.x = (temp1.z * sin(phi)) + (temp1.x * cos(phi)); temp2.y = temp1.y; temp2.z = (temp1.z * cos(phi)) - (temp1.x * sin(phi)); temp2.q = temp1.q; //YZ temp3.x = temp2.x; temp3.y = (temp2.z * cos(chi)) + (temp2.y * sin(chi)); temp3.z = (temp2.z * cos(chi)) - (temp2.y * sin(chi)); temp3.q = temp2.q; //XQ temp4.x = (temp3.q * cos(rho)) + (temp3.x * sin(rho)); temp4.y = temp3.y; temp4.z = temp3.z; temp4.q = (temp3.q * cos(rho)) - (temp3.x * sin(rho)); //YQ temp5.x = temp4.x; temp5.y = (temp4.q * cos(mu)) + (temp4.y * sin(mu)); temp5.z = temp4.z; temp5.q = (temp4.q * cos(mu)) - (temp4.y * sin(mu)); //ZQ temp6.x = temp5.x; temp6.y = temp5.y; temp6.z = (temp5.q * cos(lambda)) + (temp5.z * sin(lambda)); temp6.q = (temp5.q * cos(lambda)) - (temp5.z * sin(lambda)); //After the cumulative effect for the rotations, we assign it to *this. *this = temp6; } I hope this makes 4D rotation a little easier for you. For a full software implementation with matrices, look at: http://research.microsoft.com/~hollasch/thesis/ Steven Richard Hollasch`s 4D engine. It is research and a 4D engine. It is also the only other one in a "real" language. Its written in C for a old API, but his reasearch still alooks sound. Note on notation: For the 4th dimension, I used Q, because when you have homogneous coords, you use W as the extra coord. So to ease confusion, Q. Bugle4d

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Cool. You should keep in mind, though, that you''re expressing 4D rotation as a sequence of Euler angles. This means you have the gimbal lock problem (and in fact, though I am not totally sure, I think it''s a lot easier to accidentally get gimbal lock in 4D because there are a large number of ways to make stuff degenerate. Don''t believe me on that one, though.)

The most "preferred" representation I have seen for 4D rotations is a 2-quaternion form. Where we rotate 3D vectors as qvq*, we can rotate 4D vectors as qvr*, where q and r are different quaternions. I don''t know very much about this rotation parameterization but it is referenced in the Hestenes and Lounesto books, among other places.

-Jonathan.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Also it seems that you have the concepts down, but there are some typo''s in your code listing for 4D rotation. (The pattern of cosines and sines is messed up for the last 4 rotations... a cut-and-paste error, basically).

-Jonathan.

Share this post


Link to post
Share on other sites
I agree that doing it like that with angles is going to be pretty impractical. Alternatives that people do use include:

- the dual quaternion method suggested by Jonathan
- 4x4 matrix (fastest to use on modern processors)
- 4D rotors/spinors
- as a rotation about two planes

The last is closest to what you are trying to do. In 4D rotations take place about planes, and any rotation can carried out by rotating about two orthogonal planes through two angles. As the planes are orthogonal you need to only specify one of them, the other is just the dual of it. Together with the two angles this uniquely specifies the rotation. And for a general rotation (with non-equal engles) this way of describing the rotation is unique.

Share this post


Link to post
Share on other sites
hmmm.....

- the dual quaternion method suggested by Jonathan
- 4x4 matrix (fastest to use on modern processors)
- 4D rotors/spinors
- as a rotation about two planes

Quats I kinda get- they ara basically a complex plane notation, composed of..lesse here... a + bi + cj+ dk + el.
Functionally, the a + bi stuff from trig we all knew and loved...

4x4 matrix is a non-verbose way of handling my function.
Because algerbra is more intuitive for me than matrices, I setup my stuff as algerbra. I havn`t gotten around to optimizing yet.

4D Rotor ? Spinor ? I have never heard of either of those terms.
Could you give me a quick rundown on them or give me a link to a explanatory site ?

Rotation about planes. I read what you say, but I don`t get it.
Could you throw some quick math equations(not code) up so I can take a look at what you mean. A rephrasing might help as well. :/

Johnathan- thanks for finding the bug. I better grab my trig book and double check things again.

-Vlion

Bugle4d

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
I don''t have a lot of time right now, so I can''t answer all this stuff, but I can hit the "two planes" issue for you, and maybe a couple of other things.

Okay. In 3D any rotation is a 3x3 matrix with no nullspace (rotation doesn''t kill dimensions). Now you can see that any rotation takes place around one axis... the reason is that the axis of rotation is not changed at all by the rotation, so it must be an eigenvector of the rotation matrix.

Now a 3x3 matrix will have 3 eigenvalues, but they don''t all have to be real eigenvalues, which are the only things that we care about (since we''re dealing with a 3D real space). So what are the possibilities? You end up solving this polynomial that has 3 roots... so it has either 1 real root and two complex roots, or it has 3 real roots. (Lots of people learn that part in high school).

Okay, so if it has 3 real roots, then the "rotation" has 3 orthogonal eigenvectors. Well that means that any vector you pump through the matrix will not change direction at all... thus, the rotation is the identity.

So if the rotation is not the identity, it has 1 real root. This is the axis of rotation.

So all rotations in 3D take place around a 1D vector axis (or else they are the identity). Alternatively, you can think of the rotation as taking place aligned with the plane for which that axis is the normal vector. (You were thinking about planes as being the containers for rotation before, and this is the same thing... it''s just that the plane is not XY, YZ, or XZ, but rather some mixture of those).


Okay now let''s look at 4D for a second. It''s a fully different beast. You solve a quartic polynomial to find the eigenvalues. Again the complex eigenvalues must come in conjugate pairs. So: You have 4 real eigenvalues, or 2, or 0.

If you have 4 real eigenvalues, then again, your rotation is the identity, so that''s not very interesting.

If you have two, then your rotation is taking place in a plane. Again, this is not necessarily a plane made out of the major axes (which you were calling X, Y, Z, Q). It''s an arbitrary 2-dimensional plane. Now, since there are 4 dimensions in the space, that means that there are 2 dimensions that are orthogonal to that plane. So in addition to rotating through a 2-plane, you are also rotating *around* a 2-plane. In other words, that axis of rotation that was 1D in 3-space is now 2D in 4-space.

Now you could picture rotating through one 2D plane, and then choosing to rotate through the 2D eigenspace of that last rotation -- if you do this, you end up in a situation where *no* vectors remain parallel to how they were before you started rotating. (This is the 0-eigenvalue case).

Now this is interesting -- because the number of dimensions is even, you can decompose any 4D rotation into two orthogonal 2D rotations -- they are orthogonal because each is in the eigenspace of the other. Thus rotation in 4D is "less entangled" than 3D rotation is. All the weirdness and problems that we have with Euler angles doesn''t really exist in 4D. It''s all a lot nicer.

As a corollary, it is *impossible* to construct a rotation in 4D that only takes place around a single vector axis, like we are used to in 3D. Weird huh.

-Jonathan.

Share this post


Link to post
Share on other sites
> 4D Rotor ? Spinor ? I have never heard of either of those terms.
> Could you give me a quick rundown on them or give me a link to
> a explanatory site ?

> Rotation about planes. I read what you say, but I don`t get it.
> Could you throw some quick math equations(not code) up so I
> can take a look at what you mean. A rephrasing might help as
> well. :/

Jonathan''s described the angle/plane approach and some of the theory behind it. Rotors/spinors are more of the theory: they are one way of generalising quaternions into 4 (and higher) dimensions. The theory''s pretty involved and the best reference I''ve found on them is the book "Clifford Algebra and Spinors" by Pertti Lounesto. It''s a fairly advanced text but if you really want to understand rotations in 4D get this book.

Share this post


Link to post
Share on other sites
wow Johnathan !
What do you do in RL- teach math or something ? :D
Seriously though, it looks interesting, what you said.
Seems like I need to do some more research on high-dimensional math.

Thanks, johnb- I`ll take a look at it.

Bugle4d

Share this post


Link to post
Share on other sites
Ignoring the math for now, do you really think "So you have decided to make a 4D engine, have you ?" is a question many readers will answer with yes?

Anyway, the rest of the article seems pretty cool.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
In real life I am ... a game programmer.

Believe it or not, if you want to make good game engines for modern games, this is the kind of stuff you have to know (and a whole lot more besides).

-Jonathan.

Share this post


Link to post
Share on other sites
Quite frankly, I don`t expect a great many people to hit my site right now unless I send a update message to a major coding site.

[dream]
However, if I get everything working, I have a innotative demo in my long-range plans, and I suspect that IF I ever finish it, a great deal of people would chck out my site and read my articles, and maybe even work on a 4D engine.
[/dream]

On a less visionary note, I do release my engine source to the public, so that people can use that as a base if they want to write a modern 4D engine. The design is made for portability.

I am well aware that modern games require hordes of math.
Whether many people will make a 4D engine and/or read my artcle, I don`t know.
But I expect that as chaos theory and other strange things with "unreal" dimensions become more in peoples knowledge, more people will make hyper-d engines.
So I figure demand will slowly grow.

Johnathan- what game company ?

~V'lion

Bugle4d

Edited by - Vlion on February 21, 2002 10:44:06 PM

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Oh, I am an independent contractor right now. I work with various different companies on whatever projects they''re working on.

The most recent game I worked on to be published was Munch''s Oddysee for the Xbox. Right now I am working on a Gamecube game that''s not scheduled to be out for a long time, and also a PC game that''s more of an independent effort.

- Jonathan.

Share this post


Link to post
Share on other sites