Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dip when joining blended antialiased lines

I have a problem when joining two antialiased lines when using a blending mode, I get a dip at the point where they join. By blending mode I mean that I draw my antialiased line by calculating the ratio of line colour vs background colour, so when the ratio for a pixel is for instance 70% the new pixel is 0.7*line colour + 0.3*background colour. My antialiasing function for lines is basically made from an error function (though I suppose the same problem arises for most antialiasing functions), like this:

0.5+0.5erf(-x)

So when two lines meet, one drawn after the other, you get a dip, the joint of the two lines dips to 75% of the intensity it should be at because at that point 50% of the background was kept for the first line and then 50% of those 50% remained after the second line was drawn when 0% should be left:

1 - (0.5erfc(-x) * 0.5erfc(x))

I can only assume that it's a common problem in drawing antialiased raster graphics with joined lines so it must have a common solution, but I have no idea what this is. Thanks!

Also: Just to be clear on how the lines are drawn, in width the lines are made with a Gaussian function (e^-x*x) and both ends are rounded off using raised error functions. You can see an example of what a 10 px long horizontal line looks like by entering '0.5erfc(-x-5) * 0.5erfc(x-5) * e^(-y*y)' in WolframAlpha.

like image 423
Michel Rouzic Avatar asked Sep 16 '12 12:09

Michel Rouzic


1 Answers

Doing good-looking continuous lines composed of blended segments is in general not going to be possible if you think of them as segments - if you just think of the case of having one line and then drawing the next segment either at the same angle and then at a 90 degree angle. The pixel colors for one line depend on the angle it joins with the next line

What you then need to be thinking is segments with angled ends.

To draw it, look for literature on miter of bevel linejoin (miter is probably easier).

like image 165
tjltjl Avatar answered Sep 24 '22 00:09

tjltjl