unity 心形线函数的使用:
理论:
实践:
using UnityEngine;
using System.Collections;
public class Test : MonoBehaviour {
public float r = 5;
void Start()
{
float frame = r * .1f;
for (float i = -r; i <= r; i+= frame) {
Vector2 v = GetVec2 (i , r);
GetG (i, v.x);
GetG (i, v.y);
}
}
GameObject GetG(float x , float y)
{
GameObject g1 = GameObject.CreatePrimitive (PrimitiveType.Quad);
g1.transform.position = new Vector3 (x, y, 0);
g1.transform.localScale = Vector3.one * 0.2f;
g1.transform.SetParent (transform);
return g1;
}
Vector2 GetVec2(float x , float a = 1)
{
float p1 = a * a - x * x ;
float y1 = Mathf.Sqrt (p1) + Mathf.Pow (x * x, 1f / 3);
float y2 = -Mathf.Sqrt (p1) + Mathf.Pow (x * x, 1f / 3);
return new Vector2 (y1 , y2);
}
}
效果: