Page 1 of 1

Joining lines with circles?

Posted: Mon Jan 22, 2018 10:34 am
by ffive
How can one implement this?
Image

Re: Joining lines with circles?

Posted: Mon Jan 22, 2018 12:28 pm
by ivan
This is typically called a rounded join.
Doesn't seem to be supported according to the love2d documentation.

Re: Joining lines with circles?

Posted: Mon Jan 22, 2018 12:52 pm
by zorg
You could fake it by drawing filled circles at the end-points of line segments yourself, with love.graphics.circle.
(And make sure to optimize it so only one gets drawn between two segments, not two because of the end-points.)

Re: Joining lines with circles?

Posted: Mon Jan 22, 2018 2:41 pm
by grump
zorg wrote: Mon Jan 22, 2018 12:52 pm You could fake it by drawing filled circles at the end-points of line segments yourself, with love.graphics.circle.
Beware: lines (may?) have antialiasing applied to them, filled circles do not. The result might look unsatisfactory.
Image

You achieve better results if you draw both filled and line circles:
Image

Code: Select all

function love.draw()
	local w = 40
	love.graphics.setColor(255, 255, 255)
	love.graphics.setLineWidth(w)
	love.graphics.setLineJoin('none')
	love.graphics.line(100, 200, 240, 100, 300, 200, 320, 100)
	love.graphics.setLineWidth(2)
	love.graphics.circle('line', 240, 100, w * .5 - 1)
	love.graphics.circle('line', 300, 200, w * .5 - 1)
	love.graphics.circle('fill', 240, 100, w * .5 - 1)
	love.graphics.circle('fill', 300, 200, w * .5 - 1)
end
Tweaking the circle sizes might yield even better results.

Re: Joining lines with circles?

Posted: Mon Jan 22, 2018 6:50 pm
by ffive
Thanks for responding!
Well, i've actually tried this solution and it worked for drawing lines.
The problem is in the way how love handles line rendering internally.
Say, if you draw an outline of a slim ellipse (1:10, for example) you may notice how outline kinda 'breaks' on the ends of an ellipse
(To clarify: calling " love.graphics.ellipse( "line" , x,y , 50 , 5 ) " will draw an ellipse strerched along x-axis. So, the outline will break on the left and right side of the shape.)
The effect gets more visible if strokes are wide.
So, clarifying the question, is there a way to add some new kind of linejoin to love?
--
This isn't crucial actually, I know that might appear way too hard to implement. Just curious.

Re: Joining lines with circles?

Posted: Mon Jan 22, 2018 7:52 pm
by zorg
ffive wrote: Mon Jan 22, 2018 6:50 pm Well, i've actually tried this solution and it worked for drawing lines.
The problem is in the way how love handles line rendering internally.
Say, if you draw an outline of a slim ellipse (1:10, for example) you may notice how outline kinda 'breaks' on the ends of an ellipse
But here's what i don't understand... both with a single line or multiple line segments joined, you still never would have to draw an ellipse, only circles.

Re: Joining lines with circles?

Posted: Tue Jan 23, 2018 12:13 am
by pgimeno
There's this library: viewtopic.php?f=5&t=83841 which reimplements Löve's line drawing algorithm. That one you can modify to add a new kind of linejoin.