原理:首先要明白椭圆是怎么来的。有两个同心圆,半径分别为R,r。以这两个圆不断旋转可以得到椭圆的坐标。
代码如下:
public class ellipseCS : MonoBehaviour {
public GameObject cubeModel;
private float r = 3;
private float R = 5;
private float angle = 0;
// Use this for initialization
void Start () {
Vector3 center = cubeModel.transform.position;
for (int i=0; i<12; i++) {
GameObject cube = (GameObject)GameObject.Instantiate (cubeModel);
float hudu = (angle/180)*Mathf.PI;
float xx = center.x + R*Mathf.Cos(hudu);
float yy = center.y + r*Mathf.Sin(hudu);
cube.transform.position = new Vector3(xx,yy,0);
angle += 30;
}
}
}
最后结果: