public static Vector3 GetCircleRandomPoint(float radius, Vector3 center, SpaceTypeEnum type) { Vector3 pos = new Vector3(0, 0, 0); float range = Mathf.Sqrt(Random.Range(0.0f, 1.0f)) * radius; float angle = Random.Range(0.0f, 1.0f) * Mathf.PI * 2; if (type == SpaceTypeEnum.XY) { pos.x = Mathf.Cos(angle) * range + center.x; pos.y = Mathf.Sign(angle) * range + center.y; pos.z = center.z; } else if (type == SpaceTypeEnum.XZ) { pos.x = Mathf.Cos(angle) * range + center.x; pos.z = Mathf.Sign(angle) * range + center.z; pos.y = center.y; } else if (type == SpaceTypeEnum.YZ) { pos.z = Mathf.Cos(angle) * range + center.z; pos.y = Mathf.Sign(angle) * range + center.y; pos.x = center.x; } return(pos); }
/// <summary> /// 获取空间指定平面内圆形均匀随即分布点 /// </summary> /// <param name="number"></param> /// <param name="radius"></param> /// <param name="offval"></param> /// <returns></returns> public static Vector3[] GetCircleRandomPoints(int number, float radius, Vector3 center, SpaceTypeEnum type) { Vector3[] array = new Vector3[number]; if (number < 2) { array[0] = center; return(array); } for (int i = 0; i < number; i++) { array[i] = GetCircleRandomPoint(radius, center, type); } return(array); }