using System; using System.Collections; using System.Collections.Generic; using System.Drawing; using UnityEngine; public class MyDraw : MonoBehaviour { public GameObject pointobj; private void Start() { //DrawRound(new Vector3(1,0,0),5, 4).ForEach(a => //{ // GameObject obj = Instantiate(pointobj); // obj.transform.position = a; //}); DrawElliptic(new Vector2(10,5), 8, 4).ForEach(a => { GameObject obj = Instantiate(pointobj); obj.transform.position = a; }); } /// /// 计算圆形的坐标点 /// /// 中心点 /// 半径 /// 生成点的数量 public static List DrawRound(Vector3 centerPoint,float radius,int numPoints) { List tmplist=new List(); for (int i = 0; i < numPoints; i++) { double angleInRadians = Math.PI * 2 / numPoints * i; // 根据角度计算每个点对应的弧度值 double x = radius * Math.Sin(angleInRadians); // 通过三角函数计算x坐标 double y = radius * Math.Cos(angleInRadians); // 通过三角函数计算y坐标 //Debug.Log("Point " + (i + 1) + ": (" + x.ToString() + ", " + y.ToString() + ")"); tmplist.Add(new Vector3((float)x, (float)y, 0)+ centerPoint); } return tmplist; } /// /// /// /// /// /// /// public static List DrawElliptic(Vector2 center, float radiusX, float radiusY) { List tmplist = new List(); for (float angle = 0f; angle <= Math.PI * 2; angle += 0.5f) { double x = center.x + radiusX * Math.Sin(angle); double y = center.y - radiusY * Math.Cos(angle); tmplist.Add(new Vector3((float)x,(float)y,0)); } return tmplist; } }