draw arc

  • Hi there,
    I am not sure if this is the correct category to post this.
    I am trying to draw an arc and I cannot find any example or explanation concerning this. In the documentation it says:
    arc(center, radius, startAngle, endAngle, clockwise)
    but it didn't work.
    Assuming the center has two coordinates, I tried:
    arc((10, 10), 10, 20, 25, True) and
    arc(10, 10, 10, 20, 25, True), both didn't give a result.

    There were a few discussions and examples about arcTo(), but that didn't help me as I am trying something like this:


    Did anybody try something similar before?
    Thank you in advance for your help,

  • hello @Manufraktur,

    here is a simple example using arc() to create a slice of pie:


    from math import sin, cos, radians, pi
    x0, y0 = 500, 500 # center point (A)
    radius = 350
    angleStart = 10
    angleTotal = 55
    # draw circle with radius
    fill(0, 1, 0)
    oval(x0 - radius, y0 - radius, radius * 2, radius * 2)
    # calculate point (B) from angle and radius
    angleStartRadians = pi / 2 + radians(angleStart - 90)
    x1 = x0 + radius * cos(angleStartRadians)
    y1 = y0 + radius * sin(angleStartRadians)
    # draw pie slice using arc
    B = BezierPath()
    B.moveTo((x0, y0))
    B.lineTo((x1, y1))
    B.arc((x0, y0), radius, angleStart, angleStart + angleTotal, False)
    fill(1, 0, 0)
    # draw points labels
    fill(0, 0, 1)
    text('A', (x0, y0))
    text('B', (x1, y1))

    arc() is a bit tricky to use because point B and angleStart need to be kept in synch manually.

    notice that, in this script, B is defined with distance & angle in relation to A.

    if you prefer to define B by x/y position, as in your example, you’ll need to calculate the angle and distance of B in relation to A:

    from math import hypot, atan2, degrees
    x0, y0 = 500, 500 # A
    x1, y1 = 872, 600 # B 
    angleTotal = 55
    radius = hypot(x1 - x0, y1 - y0)
    angleRadians = atan2(y1 - y0, x1 - x0)
    angleStart = degrees(angleRadians)
    # ...same as previous example...

    hope this makes sense! cheers

  • Dear @gferreira,
    thanks for your quick reply. It seems like this could solve my problem. I will give it a try tomorrow and let you know.

    But thank you already so much for your help!

  • Dear @gferreira,
    I tried to use your suggestion it in my exercise and it worked fine. Thank you so much for your help! Amazing.
    Thank you and kind regards,