增加 GenerateCircle 传入圆的半径和需要的点数量,生成一个圆

This commit is contained in:
kercylan 2023-06-18 13:55:45 +08:00
parent 7ee7a674d7
commit 68144afa3e
1 changed files with 20 additions and 0 deletions

20
utils/geometry/circle.go Normal file
View File

@ -0,0 +1,20 @@
package geometry
import (
"github.com/kercylan98/minotaur/utils/generic"
"math"
)
// GenerateCircle 通过传入圆的半径和需要的点数量,生成一个圆
func GenerateCircle[V generic.SignedNumber](radius V, points int) Shape[V] {
angle := 2.0 * math.Pi / float64(points)
var shape = make(Shape[V], points)
for i := 0; i < points; i++ {
curAngle := float64(i) * angle
x := radius * V(math.Cos(curAngle))
y := radius * V(math.Sin(curAngle))
shape = append(shape, NewPoint(x, y))
}
return shape
}