Bug introduced in 7.0.1 or earlier -- persists through 13.2.0 or later

I have arranged a certain configuration of cubes in 3D using the following code:

   {Cuboid[{i, j - i + 1, j + 1}]},
   {i, 1, 4, 1}, {j, 1, 4, 1}], Lighting -> {{"Ambient", White}}, 
   Boxed -> False, ViewPoint -> {-1, -1, 1}]

Computing this as it is displays the following graphic: cube stack

This is fine, but the issue is what happens when you zoom in to this image in Mathematica. Doing so reveals extended edges in some of the corners shown here: enter image description here

I would like to know why this is happening, and what I need to do to get rid of the extended edges. Is this perhaps happening because Mathematica is not completely updating the graphics upon zooming?

  • 1
    $\begingroup$ I see the same problem (ver. 8.0.4 OS X). After some experimentation I found that {Opacity[0.99], Table[{Cuboid[{i, j - i + 1, j + 1}]}, {i, 1, 4, 1}, {j, 1, 4, 1}]} is a workaround. $\endgroup$ Dec 5, 2012 at 0:31
  • $\begingroup$ @StephenLuttrell, with Opacity[0.99] I still see the problem 8.0.4 on Win7x64. $\endgroup$
    – s0rce
    Dec 5, 2012 at 0:35
  • $\begingroup$ With Opacity[1] I see the problem on OS X, but Opacity[0.99] fixes it. $\endgroup$ Dec 5, 2012 at 0:37
  • $\begingroup$ Same on Linux, Opacity[0.99] fixes it. $\endgroup$ Dec 5, 2012 at 1:14
  • $\begingroup$ Linux and 8.0.4 64 bit , I still see the problem with Opacity[0.99]. $\endgroup$ Dec 5, 2012 at 12:51

1 Answer 1


Unfortunately I haven't seen this question earlier so my two cent to this problem may be a bit late. Please take my words with the appropriate suspicion because I have no knowledge of the internal implementation. My explanations are purely based on observation and what I think happens here.

Let's first make clear that we all agree on what we are seeing. The little crosses are the back edges of the cubes which shouldn't be invisible because they are covered by the faces in the front. Although your example looks really awesome in its simplicity, let us create a better one: A square and triangle polygon folded together:

Mathematica graphics

Now we could rotate the graphics so that we don't see the triangle part any more and fold it closer and closer together

    {{0, 0, 0}, {1, 0, 0}, {1, 1, 0}, {0, 1, 0}},
    {{0, 0, 0}, {1, 1/2, d}, {0, 1, 0}}
    }], Boxed -> False, PlotRange -> {{0, 1}, {0, 1}, {0, 1}}],
 {d, 0, .5}]

Mathematica graphics

As you see, the edges which shouldn't be visible at all appear through the squared polygon. This should give us the important clue what happens here.

You might already know, that the image of the 3D scene you observe is a projection from the 3D scene onto your 2D screen plane. So all polygons (and other primitives) are transformed so that the pixels on your screen give you the impression you are looking at a 3D thing. One important step in this process is to decide whether or not a pixel is covered by another one, which is closer to the camera. This step is called hidden surface determination and is crucial to give a realistic graphic.

The problem with this is, that this algorithm should work very fast because otherwise all the nifty rotations/translations of 3D graphics wouldn't work. Therefore, this stuff should be done by your graphics card which works with finite precision.

This is the reason why we see the lines, because the determination of which object covers the other was not exact enough. Fortunately, Mathematica comes with several hidden surface determination algorithms and binary space partitioning is far more exact than the algorithms in your graphics card.

So if you go to Edit->Preferences and then select the Advanced to open the Option Inspector, you will find the appropriate entry under the Graphics Options

enter image description here

Select BSPTree and rotate your graphics to update it and you'll see that the additional lines disappear even if you go really close

Mathematica graphics

Before you open the champagne, be aware that this slows down the rendering dramatically. Just make some more cubes (for instance 100 in each direction) and try to rotate the graphics and then switch the method back to Automatic and you'll see the vast difference.

  • 3
    $\begingroup$ I feel the edge problem with hardware acceleration leaves room for improvement. In some cases artifact edges are quite prominent even though the polygons are not that close... a lot of other 3D graphics software does much better here. $\endgroup$
    – Yves Klett
    Jul 30, 2013 at 8:21
  • $\begingroup$ Your explanaition reminds me z-fighting. However, the difference is that the inner part of the triangle is correctly rendered here. So if this issue is all due to the GPU's limited precision, why it won't spoil the inner part? $\endgroup$
    – luyuwuli
    Apr 25, 2016 at 4:29
  • 1
    $\begingroup$ This can be done programmatically with Style[expr, RenderingOptions -> {"3DRenderingMethod" -> "BSPTree"}]. $\endgroup$
    – Greg Hurst
    Apr 2, 2019 at 23:53
  • $\begingroup$ I think the default method is applying an offset to the edges to ensure they're visible. Graphics3D[ Table[{Cuboid[{i, j - i + 1, j + 1}]}, {i, 1, 4, 1}, {j, 1, 4, 1}], Lighting -> {{"Ambient", White}}, Boxed -> False, ViewPoint -> {-1, -1, 1}, Method -> {"EdgeDepthOffset" -> False}, ImageSize -> Large] shows this. $\endgroup$
    – Greg Hurst
    Apr 2, 2019 at 23:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.