SFML community forums

General => Feature requests => Topic started by: DimaGashko on November 13, 2018, 08:23:22 pm

Title: drawArc
Post by: DimaGashko on November 13, 2018, 08:23:22 pm
Many libraries in many languages have function like "drawArc". For example, html 5 Canvas only has ctx.arc(x, y, r, start, end):

ctx.arc(50,50,40,0,Math.PI * 2) - circle
ctx.arc(50,50,40,0,Math.PI) - half circle

But I was confused SFML didn't have something like that.
Title: Re: drawArc
Post by: Hapax on November 14, 2018, 12:15:38 am
An arc is effectively a connected set of lines in the same way that a circle can be but only some of the circle.

To draw multiple connected lines, you can use a vertex array (https://www.sfml-dev.org/tutorials/2.5/graphics-vertex-array.php).
Title: Re: drawArc
Post by: DimaGashko on November 14, 2018, 01:39:28 am
I know it, but arc it's not "one line function". I think using vertex array for arc it's the same to using vertex array for circle.

In addition, How can I set width of the line, how can I create something like that:
https://jsfiddle.net/saqkrm15/
Title: Re: drawArc
Post by: Gleade on November 14, 2018, 07:15:19 am
I think using vertex array for arc it's the same to using vertex array for circle.

Why stop there?
https://sciencestruck.com/list-of-different-types-of-geometric-shapes-with-pictures (https://sciencestruck.com/list-of-different-types-of-geometric-shapes-with-pictures)
Title: Re: drawArc
Post by: Hapax on November 14, 2018, 12:01:15 pm
SFML doesn't provide many shapes - only the basics (circle and rectangle really, although they provide an example of an ellipse).
It does, though, provide you with the ability to create your own. Vertex arrays are one of the most powerful ways to do so; it just requires that you make it yourself but it isn't that difficult.

If you would rather someone else did all of this for you, fear not! I have already created things that do this sort of thing for you (e.g. multiple lines - thick or thin, circular arcs with thickness).
Take a look at Selba Ward (https://github.com/Hapaxia/SelbaWard/wiki). Its thread on the SFML forum is here: https://en.sfml-dev.org/forums/index.php?topic=19496.0

(click to show/hide)
Title: Re: drawArc
Post by: Laurent on November 14, 2018, 12:24:03 pm
Quote
It does, though, provide you with the ability to create your own. Vertex arrays are one of the most powerful ways to do so
Don't forget to mention the simplest way to do so, ie. inheriting from sf::Shape ;)
Title: Re: drawArc
Post by: Hapax on November 14, 2018, 12:48:58 pm
That's, of course, true but I was steering the sentence towards the target shape - an arc - which, most of the time, cannot be draw using a convex shape/triangle fan.
Title: Re: drawArc
Post by: Laurent on November 14, 2018, 01:02:14 pm
You can easily fake it with a pie shape (which is convex) with transparent fill color and using only its border.

There's also thor::ConcaveShape.

The problem with Bezier spline is that you can't get an exact circle with it.
Title: Re: drawArc
Post by: Hapax on November 14, 2018, 08:27:38 pm
You can easily fake it with a pie shape (which is convex) with transparent fill color and using only its border.
Good point. Still have to implement it though and might be better to implement just the border part as a an arc object.
Question for clarity here: does the outline always work outwards from the centre of the fan and does this mean a pie shape wouldn't have an outline all the way around it?

There's also thor::ConcaveShape.
Yes, for non-convex shapes, of course.

The problem with Bezier spline is that you can't get an exact circle with it.
To be clear, I mentioned Selba Ward's Spline because it is a polyline with or without thickness, not because of its curved Bezier interpolation; it can be used without Bezier interpolation. It can be used to easily join up the vertices of the arc (points of a circle) and give it thickness if required.

Selba Ward's Ring is probably the easier option, however, with it able to be a perfect circle and calculating its points itself; it's similar to SFML's CircleShape after all. It can also have a sector of the ring specified, which, with Ring's hole, is an arc :D
Title: Re: drawArc
Post by: Laurent on November 15, 2018, 07:53:52 am
Quote
Question for clarity here: does the outline always work outwards from the centre of the fan and does this mean a pie shape wouldn't have an outline all the way around it?
Good point. It would actually have a border all around, so that wouldn't work as expected ;D

Quote
To be clear, I mentioned Selba Ward's Spline because it is a polyline with or without thickness, not because of its curved Bezier interpolation; it can be used without Bezier interpolation. It can be used to easily join up the vertices of the arc (points of a circle) and give it thickness if required.
I see.

Quote
Selba Ward's Ring is probably the easier option, however, with it able to be a perfect circle and calculating its points itself; it's similar to SFML's CircleShape after all. It can also have a sector of the ring specified, which, with Ring's hole, is an arc
Indeed, that seems the best option for an arc.