XNA C# 得到球内随机一点
经过总结,在立方体中取随机点再剔除是最快的方法,所以,找到球内的随机一点,只需如此如此:
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
namespace GameHelpers
{
public class GameHelper
{
public static Random Random = new Random();
public static float RandomNext(float min, float max)
{
return (min + (float)((max - min) * Random.NextDouble()));
}
///
///
///
球心 ///
半径 ///
public static Vector3 RandomPointInBall(Vector3 center, float radius)
{
Vector3 a;
do
{
a = new Vector3(RandomNext(-radius, radius), RandomNext(-radius, radius), RandomNext(-radius, radius));
} while (Vector3.Distance(a, Vector3.Zero) > radius);//直到随机出的点在球内..
return a + center;
}
}
Comments
呃
Comments were from migrated old data. I am too lazy so you can't add new comments yet. Sorry!