SFML community forums

Help => Graphics => Topic started by: farnoy on August 17, 2011, 10:13:03 pm

Title: Drawing Arcs / Circular sectors
Post by: farnoy on August 17, 2011, 10:13:03 pm
Hi,

How to draw a http://en.wikipedia.org/wiki/Circular_sector using generic SFML shape? I haven't seen any Arc functions in Shape class and drawing lines also doesn't cover angles.
Title: Drawing Arcs / Circular sectors
Post by: pdinklag on August 17, 2011, 10:18:30 pm
You can't technically render arcs or perfect circles, you split your arc / circle / sector up into as many triangles or straight lines as you require to get your desired level of detail.

For a perfect circle and circular sectors <= 180 degrees, a convex n-gon portion will work, but circular sectors with an angle between 180 and 360 degrees could only be represented by a concave polygon, which is why you'll probably have to go the multi-triangle way.
Title: Drawing Arcs / Circular sectors
Post by: farnoy on August 17, 2011, 10:23:42 pm
Thanks for your response.

What do you think about finding points by this equation:  http://en.wikipedia.org/wiki/Circle#Cartesian_coordinates

Code: [Select]
x = a + r cos(t)
y = b + r sin(t)


Wouldn't this give me a good level of detail?
Title: Drawing Arcs / Circular sectors
Post by: OniLinkPlus on August 18, 2011, 01:54:13 am
Quote from: "farnoy"
Thanks for your response.

What do you think about finding points by this equation:  http://en.wikipedia.org/wiki/Circle#Cartesian_coordinates

Code: [Select]
x = a + r cos(t)
y = b + r sin(t)


Wouldn't this give me a good level of detail?
That's the exact equation you need to use.
Title: Drawing Arcs / Circular sectors
Post by: Nexus on August 18, 2011, 08:37:59 am
By the way, in case you use Thor, there is a Shapes::Pie() (http://www.bromeon.ch/thor/v1.1/doc/namespacethor_1_1_shapes.html) function that creates circular sectors.

You can't use a single sf::Shape reliably, since the sector may be concave and sf::Shape only supports convex shapes. That's why the Pie() function returns thor::ConcaveShape instead.