[h1]What is 4 Dimension and how program it =)[/h1]

Let’s start simple.

[h2]1st dimension:[/h2]

Imagine a corridor.

It’s simply a line, you can look into 2 directions: forwards or backwards.

In a program this would be a 1-dimensional array, i.e.

```
int[x]
```

[h2]2nd dimension:[/h2]

Imagine a corridor that has doors to rooms.

The line we had before can now have many more lines (or corridors / rooms) along the walls of the corridor.

You see can now look into 4 directions: forwards, backwards, left, right.

In a program this would be a 2-dimensional array (an array of arrays):

```
int[x][z]
```

For rotating we use one defining angle and sin and cos:

- Sin = first and second direction (forwards, backwards)
- Cos = third and fourth direction (left, right)

In different angles we move into different directions:

- angle 90°: x+
- angle 270°: x-
- angle 0°: z+
- angle 180°: z-

[h2]3rd dimension:[/h2]

Imagine a building, which has floors, which have corridors with rooms and doors to them.

You can look into 6 directions: forwards, backwards, left, right, top and down.

In a program this would be a 3-dimensional array:

```
int[x][z][y]
```

For rotating we use 2 defining angles:

Sinus for up and down and

Cos for the XZ plane.

[h2]Dimension Plane[/h2]

Every new dimension adds a new Plane, which has 2 sides.

We only see a particular direction, if we look into it’s angle.

To show the effect, we give those directions (sides) different colors.

If you look diagonal in 3D by 2 angles, we can see 3 sides:

Green Y, Blue Z, Red X:

http://s21.postimg.org/qphh3hsqr/img1.png

If we look diagonal with only 1 angle, we can only see 2 sides:

Y Angle = 0;

http://s12.postimg.org/i5yewiopl/img.jpg

This is how it looks like, when we see 2 X sides, 1 Z side and 2 Y sides:

http://s21.postimg.org/5rbb5esw3/img0.png

Every new dimension adds 2 planar sides on one positive dimension and on one negative dimension (+/-).

They may have any color or texture.

Every new plane after 2 planes adds a new rotation axis, which is able to render it’s own 2 sides and the 2 previous planars.

In 3D the angle 0 and 180 look along the Y-axis, and 90 and 270 along the XZ plane.

[h2]4th dimension[/h2]

Imagine a group of buildings.

You can look into 8 directions: forwards, backwards, left, right, top, down, D+ and D-.

We call the new dimension D.

In a program that is a 4-dimensional array:

```
int[x][z][y][d]
```

So we now have 2 new planes on which we can travel or look along.

If it’s possible to cast a ray in 1d, 2d and 3d, it should be able to move in 4d!

And it is!

If we have a 4x4 matrix we can easy calculate Ray position with it,

but how to render it?

Let’s use raycasting.

Every pixel casts a ray, which sets the color for a pixel to the color of the obstacle it collides with.

The maths:

To cast a ray, we have to properly normalize it:

```
//2D normalize
length = sqrt(x * x + y * y)
invlen = 1 / length
x *= length
y *= length
//3D
length = sqrt(x * x + y * y + z * z)
invlen = 1 / length
x *= length
y *= length
z *= length
//4D
length = sqrt(x * x + y * y + z * z + d * d)
invlen = 1 / length
x *= length
y *= length
z *= length
d *= length
```

Moves In 3D it looks like here we have same XZ Position but We moves Top or bottom on Y plane

And Words Changed.

http://s21.postimg.org/jrdcxjumb/img3.png

http://s21.postimg.org/m9z1y8gcj/img4.png

4D matrix where

In one picture we don’t have a floor and in the second we have it.

We now moved in the D plane, but the XYZ position is still the same.

And Words Changed.

http://s21.postimg.org/mhmouqrb7/img2.png

http://s21.postimg.org/qphh3hsqr/img1.png

It’s even more interesting to see how the image will be if we make the D angle diagonal and see all 4 planes:

http://s21.postimg.org/6xfb47h6r/img6.png

Purpl Side is 4D plane color

It can be explain like

Rays that colis First World Out Of Draw Range Have Black color (1 world don’t have floor)

Rays that colis second World Have Grean color(2 world have floor)

Rays that colis Plane Side have purple color.

(purple D plane can have same Hole like Any other Plane)

I Have img this =)

Ray Progression 2D

http://s3.postimg.org/nlk6rj21r/imgsss2.jpg

Cube in 4D have 4 Planes every Plane with own color.

[h2]Ray Progression 4D[/h2]

```
y=0, z=2, x=2, d=1
y=0, z=3, x=2, d=1
y=0, z=3, x=3, d=1
y=-1, z=3, x=3, d=1// black
y=1, z=2, x=3, d=1
y=1, z=3, x=3, d=1
y=0, z=3, x=3, d=1
y=0, z=3, x=4, d=1
y=0, z=3, x=4, d=2// Purpl
y=1, z=2, x=3, d=1
y=1, z=3, x=3, d=1
y=1, z=3, x=4, d=1
y=1, z=3, x=4, d=2
y=0, z=3, x=4, d=2// Grean
```

Every new plane add Sin self and Cos prev Planes

Camera ray Projection 3D

```
ray.y += Dist * sin_Y;
ray.x += Dist * sin_X * cos_Y;
ray.z += -Dist * cos_X * cos_Y;
```

Camera ray Projection 4D

```
pos.d += Dist * sin_D;
pos.y += Dist * sin_Y * cos_D;
pos.x += Dist * sin_X * cos_Y * cos_D;
pos.z += -Dist * cos_X * cos_Y * cos_D;
```

[h2]4D matrix Img[/h2]

http://imglink.ru/thumbnails/18-05-13/1a7d01bfd2aec28ff09f6e3b11c71824.jpg

We have int[2][2][2][2]

So We have two 3D Matrix

4th Dimension give ability to Ray travel between this two 3D matrix =)

If we in int[X][Y][Z][0] we in first 3D matrix

If we in int[X][Y][Z][1] we in second 3D matrix

All simple )

If we have matrix array like in minecraft in 4D it will be 4D cube

Every Cube In First 3D matrix have Side To second 3D matrix,

So we have 2 * 2 * 2 = 8 sides(Tunnels) between two 3D matrix =)

Same as with 3D we can travel only on Free place block (Air)

So Even in 4D you only can move through the Air {Air == 0, Block == 1}

[1][2][3] D[2] = 0

[1][2][3] D[1] = 0

[1][2][3] D[0] = 1

We in [1][2][3] D[1]

Ray can move to [1][2][3] D[2] ,

but can’t move to [1][2][3] D[0] we will see wall, it can be One Color Or Texture like side in Cube

Try it yourself and make a raycasting renderer and add a 4th vector component to the ray.

Is the 4 the maximum number of possible dimensions?

No, it could be any number of dimensions. 5D, 6D or even 111D =)

Bin Link http://www.2shared.com/complete/oWYgVUbR/4d_z.html

More img

http://imglink.ru/thumbnails/18-05-13/d653a7d2ea607c183a43e8cec4602dea.jpg

http://imglink.ru/thumbnails/18-05-13/e52cffccb58864893473663b1443cba2.jpg

http://imglink.ru/thumbnails/18-05-13/35ecfe2ec0d4cd70a30beecaa2c9e444.jpg

http://imglink.ru/thumbnails/18-05-13/f659eed74c46b37cc4ad97196a743947.jpg

http://imglink.ru/thumbnails/18-05-13/d114d8b14fb83a1805cde8e67c9d921d.jpg

http://imglink.ru/thumbnails/18-05-13/63eb7b6ae08d360bf05aa150735adb5c.jpg