✨ 增加 GenerateCircle 传入圆的半径和需要的点数量,生成一个圆
This commit is contained in:
parent
7ee7a674d7
commit
68144afa3e
|
@ -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
|
||||||
|
}
|
Loading…
Reference in New Issue