阿基米德螺旋线是螺旋线的一种,具体什么样请百度谷歌之。
据说阿基米德螺旋线最方便的是使用极坐标表示,公式为 。那么我们为了在unity中绘制这个螺旋线就必须把极坐标转换为笛卡尔坐标。
可能会问怎么在unity中把极坐标转换为笛卡尔坐标呢?那是啥?
其实我也不知道。
那我们就不用极坐标了。 毕竟螺旋线就是一边匀速直线运动一边旋转。
用程序猿的思想就是 :
float x = V * T * Mathf.Cos(wt); float y = V * T * Mathf.Sin(wt); 其中V 是直线速度,W是旋转的角速度。T是时间。
好了就这样。先上代码为敬:
之所以加个
m_Round 是因为我只想让它跑一圈。 /******************************************************************** created: 9:3:2017 17:42 filename: E:\UnityDemoPro\AJMD\Assets\Archi.cs file ext: cs author: guanzhenqing purpose: *********************************************************************/ using UnityEngine; using System.Collections; public class Archi : MonoBehaviour { public Transform Target; //速度 public float Speed = 0; //角速度 public float W = 0; //直线速度 public float V = 0; public float T = 0; public float m_Round = 1; void Start () { } // Update is called once per frame void Update () { Repos(); } void Repos() { if(T >= (Mathf.PI * m_Round / W)) { return; } T += Time.deltaTime * Speed; float wt = W * T; float x = V * T * Mathf.Cos(wt); float y = V * T * Mathf.Sin(wt); Vector3 pos = Target.transform.position; pos.x = x; pos.y = y; Target.transform.position = pos; } }