Issue
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.
Solution
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)
Answered By – andy.xyz
Answer Checked By – Cary Denson (GoLangFix Admin)