From 68144afa3ef8c52b2a4e87798e301f6539f11bf1 Mon Sep 17 00:00:00 2001 From: kercylan <61743331+kercylan98@users.noreply.github.com> Date: Sun, 18 Jun 2023 13:55:45 +0800 Subject: [PATCH] =?UTF-8?q?:sparkles:=20=E5=A2=9E=E5=8A=A0=20GenerateCircl?= =?UTF-8?q?e=20=E4=BC=A0=E5=85=A5=E5=9C=86=E7=9A=84=E5=8D=8A=E5=BE=84?= =?UTF-8?q?=E5=92=8C=E9=9C=80=E8=A6=81=E7=9A=84=E7=82=B9=E6=95=B0=E9=87=8F?= =?UTF-8?q?=EF=BC=8C=E7=94=9F=E6=88=90=E4=B8=80=E4=B8=AA=E5=9C=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- utils/geometry/circle.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 utils/geometry/circle.go diff --git a/utils/geometry/circle.go b/utils/geometry/circle.go new file mode 100644 index 0000000..b6b1709 --- /dev/null +++ b/utils/geometry/circle.go @@ -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 +}