0

I'm working on a chart widget for Fyne, I use rasterx package (https://github.com/srwiley/rasterx) 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 https://github.com/srwiley/rasterx/blob/master/shapes.go#L99 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)
stroker.Stop(false)
stroker.Draw()

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.

4
  • Can you share some screenshots or a link with the actual code to have a better understanding of what's wrong or what's not working correctly?
    – Endre Simo
    May 31, 2022 at 7:49
  • I will edit this in 1 hour. But you can see the issue I've opened in the GitHub repository.
    – Metal3d
    May 31, 2022 at 8:49
  • It is not clear what px and py are, but I suspect that having the same value in the points as passed in to AddArc may relate - that is what they do in the AddEllipse function, which is desiring a completed 360degs
    – andy.xyz
    May 31, 2022 at 9:45
  • And that was exactly what I missed. I used the same vars so that makes a complete rotation. GG
    – Metal3d
    May 31, 2022 at 10:13

2 Answers 2

0

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

1
  • My god I didn't see this... Maybe I was tired. Big thanks ! You're a genius 🙂
    – Metal3d
    May 31, 2022 at 10:10
0

It’s just a guess but doesn’t the AddArc want the radian angle instead of degrees?

3
  • Actually, whatever the angle, the result is the same. I tried degree and rad... No changes 😔
    – Metal3d
    May 31, 2022 at 8:48
  • Ah yes, I see they do the translation internally for some reason.
    – andy.xyz
    May 31, 2022 at 9:44
  • That was the point. Your solution works.
    – Metal3d
    May 31, 2022 at 10:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.