71 lines
2.1 KiB
C#
71 lines
2.1 KiB
C#
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<GameObject>(pointobj);
|
|
// obj.transform.position = a;
|
|
//});
|
|
|
|
|
|
DrawElliptic(new Vector2(10,5), 8, 4).ForEach(a =>
|
|
{
|
|
GameObject obj = Instantiate<GameObject>(pointobj);
|
|
obj.transform.position = a;
|
|
});
|
|
}
|
|
|
|
/// <summary>
|
|
/// 计算圆形的坐标点
|
|
/// </summary>
|
|
/// <param name="centerPoint">中心点</param>
|
|
/// <param name="radius">半径</param>
|
|
/// <param name="numPoints">生成点的数量</param>
|
|
public static List<Vector3> DrawRound(Vector3 centerPoint,float radius,int numPoints)
|
|
{
|
|
List<Vector3> tmplist=new List<Vector3>();
|
|
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;
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="center"></param>
|
|
/// <param name="radiusX"></param>
|
|
/// <param name="radiusY"></param>
|
|
/// <returns></returns>
|
|
|
|
public static List<Vector3> DrawElliptic(Vector2 center, float radiusX, float radiusY)
|
|
{
|
|
List<Vector3> tmplist = new List<Vector3>();
|
|
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;
|
|
}
|
|
|
|
|
|
}
|