- Home /

# Morph along the 4th dimension

So I recently found out about miegakure a pretty cool looking puzzle game that works by sliding along the 4th dimension to solve mazes in interesting ways. I want to create something that plays around with that 4th dimension idea, but I'm stuck on one concept. How would I interpolate across meshes that extend into the 4th dimension. So say I have a hypercube that's rotated slightly into the 4th dimension, how do I get a 3D slice of that object? My original idea was just to only grab points matching that W value, but what if the current W value is something like 0.5 and there's an edge extending from 0 to 1. how would I find the 3d point along that edge?

You're playing with some very high level concepts friend, ones without any sort of implementation, as such there wont be many that *can* help. The concept is a fun one though, and I've watch many videos on the subject just trying to wrap my brain around it.

This one has some equations that may help: https://www.youtube.com/watch?v=iGO12Z5Lw8s

If you find answers share with the rest of us 3rd locked ;) I wish I could help more!

As for the video, I already have the equations to manipulate the object. I just want to know how to grab a 3d slice of the 4d object, not a projection.

**Answer** by Croug
·
Nov 29, 2018 at 11:51 PM

So I figured out the answer and I'll post it here for anyone interested.

So this is some pseudo code i made for the solution:

```
O // the 4d object
t = {} // the set of triangles for the slice
W // the 4d value to slice
O.W -= W // translate the w to origin
T = O.Tetrahedra
foreach tet in T
tri = {}
for e in tet.edges
if e.a.w * e.b.w < 0
k = e.a.w / (e.a.w-e.b.w)
x = (1-k)*e.a.x+k*e.b.x
y = (1-k)*e.a.y+k*e.b.y
z = (1-k)*e.a.z+k*e.b.z
tri.add ({x,y,z})
t.add(tri)
```

Note: this requires the 4d objects to be built up of tetrahedra and does not account for special cases such as when a point is exactly overlapping the selected W value.

to morph the 4d object like I described you would simply interpolate the W value.

While you have the right idea here, there are some misconceptions and terminology problems in your pseudo code. First of all you're doing an axis aligned slice. This is fine as it simplifies the calculations, however it limits the possibilities. That means the only rotation you can include here is the rotation of the object itself. However the "cutting space" is always axis aligned.

In 3d we can decompose a cube into 6 tetrahedra. In 4d we can decompose a hyper cube (tesseract) into 24 4d simplex (pentachoron or 5-cell). While slicing a pentachoron is quite a bit simpler than cutting through a hyper cube, the resulting shapes are not necessarily triangles. If you just imagine 2d cuts through 3d objects. When you cut a 3d cube by a 2d plane the 2d cross section is either a triangle, some quadrilateral, a pentagon or even a hexagon. Slicing a tetrahedron is a bit simpler but doesn't always produce triangles but also quadrilaterals. The same is true for a pentachoron

So your edge intersection code is correct, however your "tri" array could contain 4 points so would need to be split into two triangles. Note that depending in which order you store all the 10 edges of the pentachoron those 4 points do not have to be in the right order. So they need to be sorted to form a proper quadrilateral and then cut into two triangles.

Note that just as defining a 2d cutting plane in 3d space from a single point and a normal we can define a 3d cutting space in 4d from a single point and a normal. Just as in the 2d case we can determine on which "side" of the cutting space a point lies by using the 4d dot product between the normal and the relative vector from the cutting space origin and the point you want to test. If the value is positve the point is "in front" of the cutting space, if it's negative it's behind the cutting space. The dot product value can also be used to calculate the exact intersection point, just like you did. You just used the axis aligned normal (0,0,0,1) for your cutting space

I'd love to hear more about that, would you mind providing me with some pseudo code and an explanation of whats going on? and if you add it as an answer I might even accept it if it works better than my solution. I'm fairly new to the whole 4d geometry world, I just found some equations and translated them into pseudo code to try and make sense of them, but to be honest I still don't fully understand it. So anything you can do to help me understand this concept, and any reading you can point me towards would be incredibly helpful.

Also under what circumstance would slicing a tetrahedron result in a quadrilateral? I can't think of any orientation off the top of my head.

Currently i don't have much time to play around with Unity. Have you looked at this link i've already provided in the comment above? The lower two cases result in a quadrilateral. Just keep in mind that a tetrehedron consists of 4 tirangles. Any cut that cuts through all 4 triangles will result in 4 intersection points. Just think of any edge. Like every 2d edge it is only shared by two triangles. The other two triangles only share the two end points of that edge. If you cut parallel to that edge you will cut all 4 triangles.

Note that a pentachoron (the 4d equivalent of a 3d tetrehedron) is a 4d volume that is bounded by 5 3d volumes which are tetrahedra (penta=5, tetra=4). Cutting through that *may* even result in more complex shapes since there are 4 edges that meet at each of the 5 corners

Many imagine a tesseract to always look like a Schlegel projection. However this projection is just a very distorted representation of a single 4d object. In a complete 4d scene this projection doesn't really work. The normal orthographic projection is more suitable, even it's harder to visualize the 8 cells.

I don't have any pseudo code at the moment. I just wanted to point out some conceptional flaws here. A 4d object can not be decomposed into a finite set of 3d objects. A 4d object contains "4d volume" which is composed of infinite 3d volume. 3d volume is composed of infinite 2d area. 3d volume is bounded by a finite 2d area (the surface area). Likewise 4d volume is bounded by a finite 3d volume (the combined volume of the bounding cells). We can only visualize the bounding cells but not the actual object. Just like we only visualize the bounding faces of a 3d object. The main issue is that we can not imagine where that 4d volume is located between the 8 cells (tesseract) or the 5 cells (pentachoron) since we only see the shadow of the actual object.

### Your answer

### Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.

### Follow this Question

### Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Unity Mesh Rendering Issue 0 Answers

Mesh generated from bezier curve loop going outside loop 0 Answers

how to calculate this? 2 Answers