Replies: 3 comments
-
I'm glad it's useful for you! There is no specific element for arc segments so you'll need to manually use the |
Beta Was this translation helpful? Give feedback.
-
I successfully created a sector by drawing an arc with large stroke_width and no fill, you only have to fiddle with the proper parameters (radius is half the radius of the circle). |
Beta Was this translation helpful? Give feedback.
-
Following this StackOverflow answer, I got together this code, which appears to work :) Edit: this behaves weirdly if the start_angle and end_angle are the same (0° or 360° circle) from math import sin, cos, pi
import drawsvg as dw
def polar_to_cartesian(cx, cy, r, a):
a_rad = a*pi/180.0
x = cx + r * cos(a_rad)
y = cy + r * sin(a_rad)
return x,y
# angles are given in degrees
def circle_sector(d, x, y, radius, start_angle, end_angle, stroke="red", fill="black"):
start = polar_to_cartesian(x, y, radius, end_angle)
end = polar_to_cartesian(x, y, radius, start_angle)
arc_sweep = 0 if end_angle - start_angle <= 180 else 1
p = dw.Path(stroke=stroke, fill=fill)
p.M(start[0], start[1])
p.A(radius, radius, rot=0, large_arc=0, sweep=arc_sweep, ex=end[0], ey=end[1])
p.L(x,y)
p.L(start[0], start[1])
d.append(p)
width = height = 512
d = dw.Drawing(width, height, origin=(-width//2,-height//2))
for start_angle in range(0, 360, 10):
circle_sector(d, 0, 0, 200, start_angle, start_angle+5, "red", "black")
d.save_svg("sector.svg") It would be cool if this functionality would be included in the library for future users |
Beta Was this translation helpful? Give feedback.
-
Hello, I really appreciate your library, it has been useful and easy to use for me so far :)
I couldn't find a reference to drawing circle sectors in your documentation, is there a way to do it? In my case they have arbitrary angles, not just 90°s (which could be done using a rectangle clip like in the clip demo in the tutorial)
Beta Was this translation helpful? Give feedback.
All reactions