Create a "pie element" with RasterX package using AddArc


I’m working on a chart widget for Fyne, I use rasterx package ( and it works well. But I spent hours to try to make a circle arc (to create a pie chart elements) without success.

Let’s take this starting point:

cx, cy := float64(w/2.0), float64(h/2.0)
r := float64(w / 3.0)
angle := 45.0
rot := angle * math.Pi / 180.0

I take the AddArc function at to understand the principle and do:

points := []float64{r, r, angle, 1, 0, px, py}

stroker.Start(rasterx.ToFixedP(px, py))
rasterx.AddArc(points, cx, cy, px, py, stroker)

The result is a circle, not an arc.

As the rasterx package is based on SVG 2.0 spec, maybe I miss something. Can you please give me a hand to show me how to create a "pie chart element" for a given angle?

Thanks a lot.

PS: I should not use other package than rasterx, please do not tell me to use another one.


The px, py in points needs to be different to the ones passed to AddArc. This works for me:

        angle := 45.0
        rot1 := angle * math.Pi / 180.0
        rot2 := (angle - 90) * math.Pi / 180.0

        p1x := cx + r*math.Cos(rot1)
        p1y := cy + r*math.Sin(rot1)
        p2x := cx + r*math.Cos(rot2)
        p2y := cy + r*math.Sin(rot2)

        points := []float64{r, r, angle, 1, 0, p2x, p2y}


        stroker.Start(rasterx.ToFixedP(p1x, p1y))
        rasterx.AddArc(points, cx, cy, p1x, p1y, stroker)

enter image description here

Answered By –

Answer Checked By – Cary Denson (GoLangFix Admin)

Leave a Reply

Your email address will not be published.