Drawing a 90degree bend

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
Yell0w
Prole
Posts: 28
Joined: Wed Nov 21, 2012 7:40 am
Location: Norway
Contact:

Drawing a 90degree bend

Post by Yell0w »

How can i draw a 90 degree bend?
i have tried with arcs, but i only want the outer arc and not the lines leading to the center.
In the example i have covered over the part i dont want to show with a filled circle. Are there any simpler way to do this that i am missing?

Code: Select all

	love.graphics.setLine(4, "smooth")
	love.graphics.arc("line", 500, 400, 50, math.pi, math.pi/2 )
	love.graphics.arc("line", 400, 400, 50, math.pi, math.pi/2 )
	love.graphics.setColor(0,0,0)
 	emergencySolution = love.graphics.circle("fill", 500+2, 400-2, 50 )
Attachments
WW.love
(7.27 KiB) Downloaded 88 times
You can learn anything, but you cannot learn everything!
User avatar
micha
Inner party member
Posts: 1083
Joined: Wed Sep 26, 2012 5:13 pm

Re: Drawing a 90degree bend

Post by micha »

I haven't used the arc function before and actually I am surprised, it also draws the radii, when set to line mode. In my opinion (and obviously yours as well) it shouldn't do that.

Drawing a black circle on top does not solve the problem, because you don't know what color is behind.
Instead you can draw a bend by drawing many very small straight line segments. You can do this automatically(, in the sense that you don't need to enter all the coordinates by hand), but you need to write a function for that. Do you know how to use sine and cosine?
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Drawing a 90degree bend

Post by bartbes »

micha wrote: In my opinion (and obviously yours as well) it shouldn't do that.
So you want to have two different definitions for the same arc?
Because if you want to stick with one, and you don't want those lines, then.. what does filled mean?
If you go with the current definition for filled, it only makes sense that when you ask for the outlines you.. get them..
User avatar
Nixola
Inner party member
Posts: 1949
Joined: Tue Dec 06, 2011 7:11 pm
Location: Italy

Re: Drawing a 90degree bend

Post by Nixola »

I think that not drawing the radii when in line mode is useful, because they're pretty easy to write on your own, while not drawing them is a bit trickier
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
User avatar
micha
Inner party member
Posts: 1083
Joined: Wed Sep 26, 2012 5:13 pm

Re: Drawing a 90degree bend

Post by micha »

bartbes wrote:
micha wrote: In my opinion (and obviously yours as well) it shouldn't do that.
So you want to have two different definitions for the same arc?
I don't understand what you mean by that. Could you please explain?
bartbes wrote:Because if you want to stick with one, and you don't want those lines, then.. what does filled mean?
If you go with the current definition for filled, it only makes sense that when you ask for the outlines you.. get them..
I agree, that when I use filled, I want to have a sector of a circle. The current implementation of the filled option is meaningful.

But also I agree with Nixola:
Nixola wrote:I think that not drawing the radii when in line mode is useful, because they're pretty easy to write on your own, while not drawing them is a bit trickier
This would be inconsistent, but user friendly, as the radii are easy to draw "by hand", while removing them is not.

And one last thing (I had to look it up myself, I am not a native speaker): The term arc refers to the one dimensional line object on the outside of a circle. See here: http://en.wikipedia.org/wiki/Arc_%28geometry%29. This is probably why I expected the "bend" only, without radii.
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: Drawing a 90degree bend

Post by kikito »

Well, the "line" function only has one "mode". Maybe there should be a "modeless" arc function that draws just the arc, and then the one with modes also draws the radii.
When I write def I mean function.
User avatar
Ref
Party member
Posts: 702
Joined: Wed May 02, 2012 11:05 pm

Re: Drawing a 90degree bend

Post by Ref »

Other people separate the two options by using 'arc' or 'sector'.
User avatar
micha
Inner party member
Posts: 1083
Joined: Wed Sep 26, 2012 5:13 pm

Re: Drawing a 90degree bend

Post by micha »

To get back to Yell0w's original question. I wrote a function for drawing arcs:

Code: Select all

function arcline(x,y,r,alpha1,alpha2,segment)
	-- Set number of segments, if not given
	segment = segment or math.floor(math.abs(alpha1-alpha2)*10)
	-- Calculate coordinates along the arc
	coordinates = {}
	for i = 0,segment do
		currentAngle = (i/segment)*(alpha2-alpha1)+alpha1
		coordinates[2*i+1] = x+math.cos(currentAngle)*r
		coordinates[2*i+2] = y+math.sin(currentAngle)*r
	end
	--draw everything
	love.graphics.line(coordinates)
end
Just call it like love.graphics.arc, only leave away the "line".
I put it in your program, see attachment.
Attachments
arc.love
yellow's original code with an additional function for drawing arcs without radii
(1020 Bytes) Downloaded 89 times
User avatar
Yell0w
Prole
Posts: 28
Joined: Wed Nov 21, 2012 7:40 am
Location: Norway
Contact:

Re: Drawing a 90degree bend

Post by Yell0w »

Thats very elegant micha!. Maybe your function could be added as a parameter to the arc function in future releases?
Math is used alot in love and i wish i paid better attention at school :)
You can learn anything, but you cannot learn everything!
Post Reply

Who is online

Users browsing this forum: No registered users and 76 guests