![enter image description here](https://community.wolfram.com//c/portal/getImageAttachment?filename=7062ezgif.com-gif-maker.gif&userId=11733)
Imagine you would like to 3D print an impossible cube of M.C. Escher, how would you do this? Take a look at the image below, but don't scroll down yet to see how it is made. It is real 3D graphics built upon only possible geometries, so there should be a trick to it. Try to notice some details that will give it out. The image is not perfectly constructed, so look for betraying inconsistencies.
![enter image description here](http://community.wolfram.com//c/portal/getImageAttachment?filename=sdfqe53trwgfdasadb.png&userId=11733)
The cube was invented by M.C. Escher for Belvedere, a lithograph in which a boy seated at the foot of the building holds an impossible cube (below is a fragment). The impossible cube draws upon the ambiguity present in a Necker cube illustration; an impossible cube is usually rendered as a Necker cube in which the edges are apparently solid beams.
![enter image description here](http://community.wolfram.com//c/portal/getImageAttachment?filename=belvedere.jpg&userId=11733)
Designing a good optical illusion requires polishing little things. In this particular method of constructing one would need to know a bit about:
- plane curves in 3D space
- varying thickness of a spline
- controlling the reflection of light
There are alternative ways to construct it, for instance, cutting the edges:
![enter image description here](http://community.wolfram.com//c/portal/getImageAttachment?filename=Impossible_cube_different_angle.png&userId=11733)
but here I will follow a different trick illustrated below, which I saw originally in Pierpaolo Andraghetti's video.
![enter image description here](http://community.wolfram.com//c/portal/getImageAttachment?filename=imposcube.gif&userId=11733)
I start from simply drawing a cube from built-in data:
v = PolyhedronData["Cube", "VertexCoordinates"];
i = PolyhedronData["Cube", "EdgeIndices"];
Graphics3D[{Orange, Specularity[White, 20], GraphicsComplex[2 v, Tube[i, .1]]}, Boxed -> False]
![enter image description here](http://community.wolfram.com//c/portal/getImageAttachment?filename=dfgrt54ytrsgfds.png&userId=11733)
We used Tube and Specularity, which greatly increase 3D depth perception, especially for seemingly crossing edges. To replace a cube's edge with a illusion-curve I need an easy way to make it. I suggest making a very simple 2D spline:
pts = {{-1, -1}, {2.5, -2}, {2.5, -1}, {-1, 1}};
Graphics[{
{PointSize[.1], Red, Point[{1, -1}]},
{BSplineCurve[pts], Green, Line[pts], Red, Point[pts]}}, Frame -> True]
![enter image description here](http://community.wolfram.com//c/portal/getImageAttachment?filename=sdf456dsfgku455gafdgadg.png&userId=11733)
which as you can see "hugs" the red dot, - a mark for $(-1,1)$ coordinate. This visually guarantees the curve extends well enough beyond other perpendicular edge to create an impossible crossover illusion. Next we add an extra coordinate to all points and place this 2D spline into 3D:
pts3D = Transpose[Transpose[pts]~Join~{ConstantArray[-1, 4]}];
Graphics3D[
{{BSplineCurve[pts3D], Green, Line[pts3D], Red, Point[pts3D]},
{Orange, Specularity[White, 20], GraphicsComplex[2 v, Tube[i, .1]]}},
Boxed -> False, SphericalRegion -> True]
![enter image description here](http://community.wolfram.com//c/portal/getImageAttachment?filename=dafg4y5yku756yrtwgeafsdqER43.png&userId=11733)
Next I apply rotation around the "illusion" edge:
Manipulate[Graphics3D[
{{Thick, Rotate[BSplineCurve[pts3D], a Degree, {0, 1, 0}, {-1, -1, -1}]},
{Orange, Specularity[White, 20], GraphicsComplex[2 v, Tube[i, .1]]}},
Boxed -> False, SphericalRegion -> True, PlotRange -> 2]
, {{a, -65, "angle"}, 0, -90}]
![enter image description here](http://community.wolfram.com//c/portal/getImageAttachment?filename=dfg456wjhrq3tgreafv.gif&userId=11733)
We finally make a first model:
Graphics3D[
{{Orange, Specularity[White, 20],
Rotate[Tube[BSplineCurve[pts3D], .09], -65 Degree, {0, 1, 0}, {-1, -1, -1}]},
{Orange, Specularity[White, 20], GraphicsComplex[2 v, Tube[Delete[i, 2], .09]]}},
Boxed -> False, SphericalRegion -> True]
![enter image description here](http://community.wolfram.com//c/portal/getImageAttachment?filename=dsfgtr45wythrsbfxd.png&userId=11733)
As you can see it is not good. Too much light reflection pinpoints curvature of the "illusion"-edge. Also it should be slightly less thick because it should be most remote, but in reality it is of course is very close to viewer in the middle. The thickness can be fixed with variable spline thickness. For our example we need a tiny unnoticeable thickness variation, so here is an example for illustration:
Graphics3D[{Red, CapForm["Round"],
Tube[BSplineCurve[{{0, 0, 0}, {1, 1, 0}, {1.2, 2, 0}, {.6, 1.8, 0},
{0, 1.3, 0}, {-.6, 1.8, 0}, {-1.2, 2, 0}, {-1, 1, 0}, {0, 0,0}}],
{.1, .1, .1, .1, .3, .1, .1, .1, .1}]}]
![enter image description here](http://community.wolfram.com//c/portal/getImageAttachment?filename=sgdft3qtegsfdergsfd.png&userId=11733)
And the light is fixed by removing Specularity and providing a few sources to uniformly illuminate the "illusion"-edge:
Graphics3D[
{{Rotate[Tube[BSplineCurve[pts3D],{.09,.06,.06,.09}],-65 Degree,{0,1,0},{-1,-1,-1}]},
{GraphicsComplex[2v,Tube[Delete[i,2],.09]]}},
Boxed->False,SphericalRegion->True,
Lighting->{
{"Directional",Orange,{{5,5,4},{5,-10,0}}},
{"Directional",Orange,{{5,5,4},{5,5,0}}},
{"Directional",Orange,{{5,5,4},{5,50,0}}}}]
![enter image description here](http://community.wolfram.com//c/portal/getImageAttachment?filename=sadf345tyuffs645tyrsgd.png&userId=11733)
And this is much better, but once you know the trick you can notice light variations that betray curvature. There is a lot of room for improvement of course, feel free to post your ideas. I would need to take a better care of corner junctions bending the spline as Pierpaolo Andraghetti did. The original by Pierpaolo Andraghetti is exquisitely crafted, a beautiful work, nevertheless you still can see imperfections. For example, his beam, is rectangular as contrasted with mine which is round. If you look carefully along Pierpaolo's "illusion"-edge you can notice that sharp edge is getting vague, relative to other vertical edges. Constructing this in real life perfectly is a challenge, lighting is subtle. I think the best would be to give little lighting to allow the brain to "guess" and imagine the rest. This and other code for making GiFs is in the attached notebook.
![enter image description here](http://community.wolfram.com//c/portal/getImageAttachment?filename=4400ezgif.com-optimize.gif&userId=11733)