How do I draw a segment of a circle?

What’s the easiest way to draw a circle but only from angle_1 to angle_2?

You can use the arc function.
Here is an example:

#let circle-segment(start, stop) = canvas({
  import draw: *

  let arc-color = rgb("#76BDE9")
    
    //Draw the blue circle segment in three parts/lines/strokes
    merge-path(
      fill: arc-color,
      stroke: none,
      {
      line((0,0), (start, 1))
      arc((0,0), start: start, stop: stop, anchor: "origin")
      line((0,0), (stop, 1))
    })

    //Draw the black start and stop lines
    line((0,0), (start, 1.3))
    line((0,0), (stop, 1.3))
})

The result could look something like this:
https://typst.app/project/rwkY7GDDuI8iy8QXzanAF2

3 Likes

Thanks a lot, I was especially missing

arc(..., anchor:"origin")

Hi @M4R1S, thanks for your question! If you feel the response you got has sufficiently answered your question, be sure to give it a checkmark. This will help others find the solution in the future. Thanks!

(also, thanks @Mathemensch for fixing the line in your “full rotation” example, it was bugging me in the question’s example screenshot :stuck_out_tongue:)

2 Likes