Public Group

# 4D Arrays?

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

## Recommended Posts

Im trying to make a 4D array class. But I dont know the equation that you need when you are locating a certain cell/index in the array.

For 2d arrays I know it is y(height)*width + x. I also know it for the 3d array but not on the top of my head. But what is it for a 4D array?

hmmm maybe its pointless since you cant even visualize a 4d array... Since what is considered the 4th dimension? I know the 3d has height width and depth but what is in 4d?

##### Share on other sites
height, widht, depth, and whatever. You can call it time, or monkeyballs, it doesn't really matter.
Or rather, it depends on what you want your fourth dimension to mean.

x + y*width + z*height*width + w*height*width*depth.

you can expand it to as many dimensions as you like.

Why do you need a 4D array anyway? sounds a bit exotic to me. Edited by Olof Hedman

##### Share on other sites
If you don't know what is in a 4D array, why do you bother to make a 4D array?
Also, when we come to a multiple dimension array, especially so high dimension 4D, we should consider better data structure rather than a plain array.
So if you want to store X, Y, Z, D in a 4D array, how about store them in a 1D array with a structure.
struct Item {
int X;
...
};
Item myArray[100];
Isn't that clearer?
If you are not using C/C++, just make Item a class. Edited by wqking

##### Share on other sites
4D "can" be visualized in 3D: http://en.wikipedia.org/wiki/Tesseract
The fourth dimension can called whatever you like, some people say it's time, some people say it's space and some say it's an object in itself.

Here is a nice link about how you project the 4D in 3D: http://steve.hollasc...s/chapter4.html
Four-dimensional geometry: http://steve.hollasc...s/chapter2.html

##### Share on other sites
The code in my post projects 4D into 1D

the first 3 dimensions doesn't have to be height, width, and depth either, thats only if you choose to represent space with it.

mathematically, they can be anything.

##### Share on other sites
im making it for learning purposes. The book goes up to making a 3d array class and I thought maybe making a 4d class myself would be good exercise

##### Share on other sites
Why aren't you just using
 int array[3][4][5][6]; //or std::vector< std::vector< std::vector< std::vector< /*your Type*/ > > > > array; 

Using a naked C++ array is usually bad for this and even if you have to if you use only one array you end up with a uniform grid like array only, jagged arrays wouldn't be possible you would need to use a "type****" for that and the just looks ugly. Edited by NightCreature83

##### Share on other sites

im making it for learning purposes. The book goes up to making a 3d array class and I thought maybe making a 4d class myself would be good exercise

That makes sense.
Hope this Wiki helps you,
http://en.wikipedia.org/wiki/Array_data_structure#Multidimensional_arrays

##### Share on other sites

4D "can" be visualized in 3D: http://en.wikipedia.org/wiki/Tesseract

A "funny" note on those pictures (wich I feel is often forgotten/omitted) is that it isn't just a 3D projection, but a 2D projection of a 3D projection of a 4D object
Might sound irrelevant, but I found that this realisation made me understand the 4D objects better. you have the same kind of information loss from 3D to 2D as you do in 4D to 3D, so in the same way an animation shows 3D objects better in 2D, you "see" the 4D objects better if you rotate it. (as is shown in the animated pictures) Edited by Olof Hedman

##### Share on other sites

[quote name='EngineProgrammer' timestamp='1354869730' post='5008047']
4D "can" be visualized in 3D: http://en.wikipedia.org/wiki/Tesseract

A "funny" note on those pictures (wich I feel is often forgotten/omitted) is that it isn't just a 3D projection, but a 2D projection of a 3D projection of a 4D object
Might sound irrelevant, but I found that this realisation made me understand the 4D objects better. you have the same kind of information loss from 3D to 2D as you do in 4D to 3D, so in the same way an animation shows 3D objects better in 2D, you "see" the 4D objects better if you rotate it. (as is shown in the animated pictures)
[/quote]
The real problem with 4D is that you can't imagine it so you have no idea what the real representation looks like, our brains are wired for a 3D world. So to us even a 2D image of a 3D object will actually still look 3D because our brain will try an interpret the depth in the image anyways.

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 14
• 14
• 45
• 22
• 27
• ### Forum Statistics

• Total Topics
634043
• Total Posts
3015206
×