How does the degree tuple in wand's draw.arc work? Advanced math? Sorcery?

44 Views Asked by At

wand's draw.arc takes three arguments:

  • starting coordinates
  • ending coordinates
  • a "pair which represents starting degree, and ending degree"

What is the underlying math being used here? Unfortunately, only one example is given:

from wand.image import Image
from wand.drawing import Drawing
from wand.color import Color

with Drawing() as draw:
    draw.stroke_color = Color('blue')
    draw.stroke_width = 2
    draw.fill_color = Color('white')
    draw.arc(( 25, 25),  # Stating point
             ( 75, 75),  # Ending point
             (135,-45))  # From bottom left around to top right
    with Image(width=100,
               height=100,
               background=Color('lightblue')) as img:
        draw.draw(img)
        img.save(filename='draw-arc.gif')

I've marked 25,25 and 75,75 in this image:

enter image description here

I'm mystified on how 135 and -45 relate to those two points? I understand the first two (x,y) arguments but the start/end tuple confuses me.

2

There are 2 best solutions below

1
emcconville On BEST ANSWER

Check out ImageMagick's Primitive Draw Commands usage guide. The start & end points define the rectangle where the arc will be drawn.

The 'arc' draw primitive is listed with rectangles as it is really just a 'ellipse' that is fitted inside the 'rectangle' defined by the two coordinates. Partial arcs are rarely used as it can be hard to determine the end points unless the angles are limited to multiplies of ninety degrees.

It may be worth looking into path_* methods, as Drawing.path_elliptic_arc() might behave closer to what you would expect.

Edit

I'm mystified on how 135 and -45 relate to those two points?

The last tuple defines which part of the ellipse to draw. We express this by start angle, and end angle relative 0° facing east.

maths

0
fmw42 On

Adding to EMConville's answer, the two points define the bounding rectangle (blue) for a full ellipse (red) that fits within the rectangle. The two angles define the start and end of the elliptic arc (black drawn over the red). Here is Imagemagick command line code to demonstrate:

magick -size 100x100 xc:skyblue \
-fill none -stroke red -draw "arc  25,25, 75,75 0,360" \
-fill none -stroke blue -draw "rectangle 25,25, 75,75" \
-fill none -stroke black -draw "arc  25,25, 75,75 135,-45" \
draw_arc_partial.gif

enter image description here