3
$\begingroup$

The following Graphics behavior is annoying. Plotting several identical lines over each other makes the line thicker and thicker. But the correct behavior should be - the line should stay same no matter how many times I plot identical line over it.

Input:

Table[Graphics[{Line[{{0, 0}, {1, 1}}], 
   Table[Line[{{1/10, 0}, {1/10 + 1, 1}}], n], 
   Inset[n, {1/2, 1}]}], {n, {1, 2, 5, 10, 100, 1000}}]

Export["C:\\gra.gif", %, "DisplayDurations" -> 1, 
 AnimationRepetitions -> Infinity]

Output:

multiple identical lines

For example this behavior makes images ugly, since the lines are not evenly thick:

Input:

et[p_] := {Transparent, 
  Triangle[(-p*{1/2, Sqrt[3]/2} + {0, 
         Sqrt[3]/6 Mod[Total[p], 2]}) + # & /@ ({{-(1/2), -(1/(
         2 Sqrt[3]))}, {1/2, -(1/(2 Sqrt[3]))}, {0, 1/Sqrt[3]}}*(-1)^
      Total[p])]}
Graphics[{{EdgeForm[Black], 
   et /@ {{0, 0}, {0, 1}, {-1, 1}, {1, 1}, {-1, 2}, {0, 2}, {1, 
      2}, {2, 2}, {-2, 2}, {0, 3}, {1, 3}, {2, 3}, {-1, 3}, {-2, 
      3}, {-3, 3}, {3, 3}, {-1, 4}, {0, 4}, {1, 4}, {2, 4}, {3, 
      4}, {-2, 4}, {-3, 4}, {-4, 4}, {4, 4}, {0, 5}, {1, 5}, {2, 
      5}, {3, 5}, {4, 5}, {-1, 5}, {-2, 5}, {-3, 5}, {-4, 5}, {-5, 
      5}, {5, 5}}}}]

Output:

equilateral triangles

EDIT:

Here are three version of the same image.

First with option Antialiasing -> True with duplicate lines.

Second with option Antialiasing -> False with duplicate lines.

Third with option Antialiasing -> True with manually removed duplicate lines.

Antialiasing -> True with duplicate lines Antialiasing -> False Antialiasing -> True and manually removed duplicate lines

Clearly the third is the best quality. But in my opinion the first image should look exactly like the third one without me manually removing duplicate identical lines.

$\endgroup$
5
  • 4
    $\begingroup$ I think this problem is not specific to Mathematica. When there is anti-aliasing to make lines look smooth, the line isn't composed of only black and white pixels but of different (semi-translucent) shades of gray. When you superpose several of these lines, all shades of grey become darker and the line appears thicker. The effect should disappear the more you zoom in or when you print the graphic. I think the only way to prevent it is to remove the additional lines. $\endgroup$
    – banone
    Commented Jan 27, 2020 at 14:07
  • $\begingroup$ I do not know in detail how anti-aliasing works but I think it should not be applied after each individual line was drawn but only once after complete drawing. This way I do not see how grey pixels can add up to make the line thicker. $\endgroup$ Commented Jan 27, 2020 at 14:20
  • 5
    $\begingroup$ Anti-aliasing isn't applied after each line is drawn. It occurs as the line is rasterized (converted from a vector representation into pixels). $\endgroup$
    – Matt
    Commented Jan 27, 2020 at 14:44
  • $\begingroup$ Whether the cause is anti-aliasing or not - the point was that Mathematica should be able to take care of it automatically - the more it is a mathematical software not a graphical. And from a mathematician perspective if we have two lines - one from point $A$ to point $B$ and another form point $A$ to point $B$ - then it should be depicted exactly same as if we have just one line form $A$ to $B$. $\endgroup$ Commented Jan 27, 2020 at 20:39
  • 2
    $\begingroup$ From a graphical rendering point of view, I disagree that Mathematica should take care of it. What if you shift the position of one of the overlapping lines by 10^-5 (mimicking a possible numerical error)? Does that count as lines overlapping, or not? Making Mathematica check the position of each and every graphical element would be very clumsy. My opinion is that the user should remove graphical elements if they are not to be rendered, including overlapping lines. $\endgroup$
    – QuantumDot
    Commented Jan 29, 2020 at 0:31

1 Answer 1

4
$\begingroup$

As suggested in the comments, the problem is the anti-aliasing. Setting it to false solves the problem.

Table[Graphics[{Line[{{0, 0}, {1, 1}}], 
                Table[Line[{{1/10, 0}, {1/10 + 1, 1}}], n], 
                Inset[n, {1/2, 1}]}
              ] // Style[#, Antialiasing -> False]&
      , {n, {1, 2, 5, 10, 100, 1000}}]
$\endgroup$
2
  • $\begingroup$ This is a solution if you do not care about quality of the image. For me it is not a solution. I want anti-aliasing to be turned on and also to display multiple identical lines as one line not a bunch of lines. See my edit of the question with three examples of images. $\endgroup$ Commented Jan 28, 2020 at 20:12
  • $\begingroup$ "I want anti-aliasing to be turned on and also to display multiple identical lines as one line not a bunch of lines." - this seems quite unreasonable $\endgroup$ Commented Jan 29, 2020 at 0:51

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.