How to put one object both in front and behind another object at the same time?


I've attempted (as a test) to make a circle with a bar going through it. The bar should go under one side of the circle and over the other.

I've done this by splitting the circle into two objects, however there are visible seams where the split was done, even though the paths match up exactly.

enter image description here

Also, the shadow under the left part of the circle doesn't go on top of the bar like it ought to, and I can't think of any way to fix this without splitting the shadow object too.

Is there a better way to do this?

If needed I can also upload the svg.

10/21/2014 12:25:00 AM

Accepted Answer

The gap you see is due to an imperfect rendering by Inkscape and not necessarily a problem depending on how you export or use your SVG (as long as you cut precisely). The shadows however will likely cause problems, when cut up (which is the only way I can think of to make them right).

Here is my solution to this. As an example, I cut up a plain bar, because it’s easier. But cutting up the outer circles has some advantage, which I will mention later. First an image:

Some overlay techniques

The left uses transparent objects (one blue, one red) for demonstration, the right shows the result.

  • In the top, I reproduced what you did and just cut my bar. This leads to the aforementioned gap on some zoom levels or pixel exports (it may also happen in some PDF renderers or similar).
  • In the middle, I let the two halves of the bar overlap, which avoids the gap but lets the bar appear slightly thicker around the cut (you may have to zoom in to see this).
  • In the bottom, I used what I recommend to do¹. The biggest overlap is half the bar’s width. I could not find any zoom level or export for which this produced an undesired aliasing effect (i.e., a gap or a thickened bar).

Now, let’s have a look at the shadows:

enter image description here

The order is the same as above. On the right, we have the shadows alone for better illustration.

  • The shadow for the simple cut looks okay, but we can see, that it’s somewhat weaker at the cutting position. This becomes more of a problem for fuzzier shadows.
  • In the middle, we have a significant problem.
  • In the bottom, we can make out the position of the cut, but the shadow is neither weaker nor stronger, just distributed differently. In particular, it does not get any worse, if the shadow gets fuzzier. The cut is even less visible, if it does not happen on a straight segment, which is why it may be advantageous better for you to cut the circles instead of the middle bar.

¹ You can achieve this as follows:

  1. Make the cut as normal.
  2. Add a node in the middle of each cut edge.
  3. Move each node outwards by one quarter of the width² of whatever you cut.

² For this value, I empirically found the distortion of the shadow to be lowest.

6/22/2016 4:24:00 PM