如何均匀地将球体表面上的点随机化? [英] How to randomize points on a sphere surface evenly?

查看:138
本文介绍了如何均匀地将球体表面上的点随机化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



这是我试过的:

  rx = rand(0.0f,PI * 2.0f); 
ry = rand(0.0f,PI);
x = sin(ry)* sin(rx)* range;
y = sin(ry)* cos(rx)* range;
z = cos(ry)* range;

其结果为:

img http://img716.imageshack.us/img716/3320/sphererandom.jpg





  rx = rand(-1.0f,1.0 F); 
ry = rand(-1.0f,1.0f);
rz = rand(-1.0f,1.0f);
x = rx *范围;
y = ry *范围;
z = rz *范围;

其结果为:

img2 http://img710.imageshack.us/img710/5152/squarerandom.jpg



(虽然没有制作一个球体,但是opengl并没有说明有什么区别。)

看,总是有一些角落,平均点数多。我怎样才能在一个球体上创建随机点,并将点均匀分布?

解决方案

你可以这样做

b
$ b

  z = rand(-1,1)
rxy = sqrt(1-z * z)
phi = rand 0,2 * PI)
x = rxy * cos(phi)
y = rxy * sin(phi)

这里rand(u,v)从interal [u,v]中抽取一个统一的随机数

Im trying to make stars on the sky, but the stars distribution isnt even.

This is what i tried:

rx = rand(0.0f, PI*2.0f);
ry = rand(0.0f, PI);
x = sin(ry)*sin(rx)*range;
y = sin(ry)*cos(rx)*range;
z = cos(ry)*range;

Which results to:

img http://img716.imageshack.us/img716/3320/sphererandom.jpg

And:

rx = rand(-1.0f, 1.0f);
ry = rand(-1.0f, 1.0f);
rz = rand(-1.0f, 1.0f);
x = rx*range;
y = ry*range;
z = rz*range;

Which results to:

img2 http://img710.imageshack.us/img710/5152/squarerandom.jpg

(doesnt make a sphere, but opengl will not tell a difference, though).

As you can see, there is always some "corner" where are more points in average. How can i create random points on a sphere where the points will be distributed evenly?

解决方案

you can do

z = rand(-1, 1)
rxy = sqrt(1 - z*z)
phi = rand(0, 2*PI)
x = rxy * cos(phi)
y = rxy * sin(phi)

Here rand(u,v) draws a uniform random from interal [u,v]

这篇关于如何均匀地将球体表面上的点随机化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆