Circles - Maths317
To draw a circle knowing the radius (r) and the center of the circle at point \((x_0, y_0)\). The circle formulas are:
\(x_1 := x_0 + (r \times sin\theta ) \)\(y_1 := y_0 + (r \times cos\theta ) \)
Loop through 360 and set the radius to the loops index, and use the formula above to get all the points of the circle.
Test Code
package main
import (
"github.com/disintegration/imaging"
"image/color"
"math"
)
func main() {
width := 500
height := 300
img := imaging.New(width, height, color.White)
radius := 50
for angle := 0; angle <= 360; angle++ {
angleInRadians := float64(angle) * (math.Pi / 180)
x := float64(radius) * math.Sin(angleInRadians)
y := float64(radius) * math.Cos(angleInRadians)
img.Set(width/2 + int(x), height/2 + int(y), color.Black)
}
err := imaging.Save(img, "out_circles1.png")
if err != nil {
panic(err)
}
}