Joining lines with circles?

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
ffive
Prole
Posts: 16
Joined: Wed Oct 22, 2014 3:22 pm

Joining lines with circles?

Post by ffive »

How can one implement this?
Image
.·˙·.·˙·.·˙·.·˙·.·˙·.·˙·.·˙·.·˙·.·˙·.·˙·.·˙·.·˙·.·˙·.·˙·.·˙·.·˙·.·˙·.·˙·.·˙·.·˙
User avatar
ivan
Party member
Posts: 1911
Joined: Fri Mar 07, 2008 1:39 pm
Contact:

Re: Joining lines with circles?

Post by ivan »

This is typically called a rounded join.
Doesn't seem to be supported according to the love2d documentation.
User avatar
zorg
Party member
Posts: 3444
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Joining lines with circles?

Post 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.)
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
grump
Party member
Posts: 947
Joined: Sat Jul 22, 2017 7:43 pm

Re: Joining lines with circles?

Post 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.
User avatar
ffive
Prole
Posts: 16
Joined: Wed Oct 22, 2014 3:22 pm

Re: Joining lines with circles?

Post 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.
.·˙·.·˙·.·˙·.·˙·.·˙·.·˙·.·˙·.·˙·.·˙·.·˙·.·˙·.·˙·.·˙·.·˙·.·˙·.·˙·.·˙·.·˙·.·˙·.·˙
User avatar
zorg
Party member
Posts: 3444
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Joining lines with circles?

Post 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.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
User avatar
pgimeno
Party member
Posts: 3550
Joined: Sun Oct 18, 2015 2:58 pm

Re: Joining lines with circles?

Post 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.
Post Reply

Who is online

Users browsing this forum: No registered users and 82 guests