Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: drawArc  (Read 9898 times)

0 Members and 1 Guest are viewing this topic.

DimaGashko

  • Newbie
  • *
  • Posts: 2
    • View Profile
drawArc
« 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.

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: drawArc
« Reply #1 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.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

DimaGashko

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: drawArc
« Reply #2 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/
« Last Edit: November 14, 2018, 01:48:10 am by DimaGashko »

Gleade

  • Jr. Member
  • **
  • Posts: 55
    • View Profile
Re: drawArc
« Reply #3 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

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: drawArc
« Reply #4 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. Its thread on the SFML forum is here: https://en.sfml-dev.org/forums/index.php?topic=19496.0

(click to show/hide)
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: drawArc
« Reply #5 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 ;)
Laurent Gomila - SFML developer

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: drawArc
« Reply #6 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.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: drawArc
« Reply #7 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.
« Last Edit: November 14, 2018, 02:20:58 pm by eXpl0it3r »
Laurent Gomila - SFML developer

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: drawArc
« Reply #8 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
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: drawArc
« Reply #9 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.
Laurent Gomila - SFML developer