0

I am trying to draw a thick diagonal line across a square divided into two colors on its diagonal. It is subtle in the PNG below, but if you compile the MWE and zoom in, you will see a single-pixel black line along the side of the blue diagonal on the red side, but not on the yellow side.

I have also drawn shifted versions of the diagonal only on the red and yellow fields. The effect is only observed on the upper part of the diagonal in the red field and is not observed at all in the yellow field. It is also observed on a horizontal line over the red field, which leads me to believe this isn't a rotation issue.

I have looked at the output PDF in Preview.app and Adobe Reader on MacOS and both exhibit the same behavior, so I believe this to not be an artifact of the PDF viewer.

The final form of this image will be as a small GIF and the single black pixel becomes a noticeable shadow in the scaled-down version.

Why is this happening? How can I prevent it?

NOTE: the actual diagonal line will be a Bézier curve using (point) .. controls (point) .. (point), so any solution should take that into account. Perhaps this should be in the MWE, but since I observed it in the case of a simple (point) -- (point) I think this is a more general issue. (This also explains why I use a scope and a clip for the red triangle instead of just drawing one, since the real clipping path will also be a curve.)

\documentclass[tikz]{standalone}
\begin{document}
\begin{tikzpicture}[x=1cm, y=1cm]
    \clip (0, 0) rectangle (100, 100);
    \fill[yellow] (0, 0) rectangle (100, 100);
    \begin{scope}
        \clip (0, 0) -- (0, 100) -- (100, 100) -- cycle;
        \fill[red] (0, 0) rectangle (100, 100);
    \end{scope}
    \draw[blue, line width=6cm, line cap=rect] (0, 0) -- (100, 100);
    \draw[blue, line width=6cm, line cap=rect] (-10, 0) -- (90, 100);
    \draw[blue, line width=6cm, line cap=rect] (10, 0) -- (110, 100);
    \draw[blue, line width=6cm, line cap=rect] (0, 50) -- (100, 50);
\end{tikzpicture}
\end{document}

output of MWE

EDIT: small GIF version to show the shadow persisting as a rasterized image small GIF version showing shadow in rasterized image

  • 3
    Looks like optical ilusion because the contrast with red. Try with \fill[red!20]. – Sigur Nov 20 '18 at 15:54
  • It disappears with the lighter color, but I don't think it's an illusion. If you zoom to see only the bottom edge of a blue line on red, there is no black line--why wouldn't it be symmetric? Also see the small GIF version I added where a noticeable shadow exists; if you zoom in there, you can see black/grey pixels instead of a direct transition from red to blue. – Scott Colby Nov 20 '18 at 16:05
  • Okay, maybe I'm crazy. Looking at the GIF more closely I see that the colors on the pixels on opposite sides of the line are the same. If there aren't any other ideas I'd believe the optical illusion explanation. – Scott Colby Nov 20 '18 at 16:09
  • I can see nothing... where is the black line supposed to be? – Symbol 1 Nov 24 '18 at 2:32
  • Yeah, it's my fault; I fell for an illusion. – Scott Colby Nov 24 '18 at 3:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.