유니티(Unity) | Random Point On Sphere
Programming/Unity
2017. 10. 8. 13:59
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | public Vector3 RandomPointOnSphere(float radius) { float u = Random.Range(0f, 1f); float v = Random.Range(0f, 1f); float theta = 2f * Mathf.PI * u; float phi = Mathf.Acos(2f * v - 1); Vector3 vec; vec.x = radius * Mathf.Sin(phi) * Mathf.Cos(theta); vec.y = radius * Mathf.Sin(phi) * Mathf.Sin(theta); vec.z = radius * Mathf.Cos(phi); return vec; } | cs |