How to rotate in 4 dimensions?
Asked Answered
O

3

6

I am trying to implement 4D Meshes for a game. However, I have found a little problem, I have got no clue how to rotate things in 4-dimensional space.

I have looked across the internet and have found the following for 2-dimensions:

2D rotations

and the following for 3-dimensions:

3D rotations

However, when I search for things in 4D I don't find people that have good answers with matrixes showing the exact transformations to perform.

The code I am writing is in C# however my goal is to make this post useful for everyone so I won't post any code here (also because I have no actual rotation code right now).

The points (vertices) are currently represented as 4 float values (x,y,z,w). The rotation can be represented in any way you'd like.

If anyone has a good explanation with some matrixes or a different way Thanks!!

Optometer answered 30/10, 2019 at 13:38 Comment(3)
Take a look at this answer: math.stackexchange.com/questions/386478/…Accent
Note that the above answer does not specify the most general form of 4D rotations.Accent
Does this answer your question? How to use 4d rotorsPrognosis
O
4

Alright, The guy who answered and got the bounty was wrong, I don't want to just rotate 180 degrees -_- . What about 90, what about 45, what about 69.420 or 3.432434? We need to know that as well.

So I did actually figure it out myself yesterday. You just select a plane, for example xy That means the zw coordinates will change. Now use the 2D matrix to rotate those points. Do this for every axis, a total of 6 to be able to rotate around every axis.

Optometer answered 25/11, 2019 at 11:30 Comment(0)
M
0

I think what you mean is how do you rotate points defined in homogeneous coordinate (with 4 values). This is done as follows:

rot

You pad the regular 3×3 rotation matrix R with zeros and ones to get a 4×4 rotation matrix.

If you want to combine a translation with (dx,dy,dz) before the rotation then you add the translation vector to the last column

rot2

The above is expanded as follows with regular 3×1 vectors

rot3

Moeller answered 25/11, 2019 at 17:9 Comment(0)
E
-2

Rotating in-place means you modify the matrix itself, without creating a new one. But, if you're rotating 90 degrees, you can of course only rotate in-place if the matrix is square. However, you can always rotate in-place if you're rotating 180 degrees. Let's take a non-square matrix:

{ a, b, c, d, e, f },
{ g, h ,i, j, k, l },
{ m, n, o, p, q, r }

If we rotate it 180 degrees, we end up with:

{ r, q, p, o, n, m },
{ l, k, j, i, h, g },
{ f, e, d, c, b, a }

You can see that an item at [r, c] ends up at [#rows - r - 1, #columns - c - 1]. (0-based of course), so b at [0, 1] ends up at [3 - 0 - 1, 6 - 1 - 1]

The method you can use is: first swap a and r, then b and q, etc. This is similar to reversing a 1-dimensional array, just in 2 dimensions. Just as when reversing a 1-dimensional array, we only go halfway: the last 2 items we swap are i and j. I made the method generic, so you can rotate any matrix with it.

static void Rotate180<T>(T[,] matrix) {
    int rowCount = matrix.GetLength(0), columnCount = matrix.GetLength(1);
    int max = rowCount * columnCount / 2, m = 0;
    for (int r = 0; ; ++r) {
        for (int c = 0; c < columnCount; ++c) {
            Swap(matrix, r, c, rowCount - r - 1, columnCount - c - 1);
            if (++m >= max) return;
        }
    }
}

static void Swap<T>(T[,] matrix, int r1, int c1, int r2, int c2) {
    T temp = matrix[r1, c1];
    matrix[r1, c1] = matrix[r2, c2];
    matrix[r2, c2] = temp;
}
Eboh answered 24/11, 2019 at 15:25 Comment(1)
The author of the question asked about completely different thing.Accent

© 2022 - 2024 — McMap. All rights reserved.