给定球体上的随机点 [英] Random Point on a given Sphere

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

问题描述

我想在给定的球体上选择随机点.这个页面很好地解释了它:

I want to select random points on a given sphere. This page explains it quite well:

http://mathworld.wolfram.com/SpherePointPicking.html(获得点使得球体上的任何小区域......")

http://mathworld.wolfram.com/SpherePointPicking.html ("To obtain points such that any small area on the sphere...")

但我不确定我是否在 JavaScript 中正确实现了它,因为我几乎没有办法正确测试它:

But I'm not entirely sure if I'm implementing it correctly in JavaScript, as I have little means of testing it properly:

var u = random();
var v = random();
var angle1 = 2 * Math.PI * u;
var angle2 = Math.pow(Math.cos (2 * v - 1), -1);
X = X0 + (radius * Math.sin(angle1) * Math.cos(angle2));
Y = Y0 + (radius * Math.sin(angle1) * Math.sin(angle1));
Z = Z0 + (radius * Math.cos(angle1));

我特别不确定我是否正确理解了 cos(-1),我将其实现为-1 次方的余弦".

I'm especially unsure about if I've understood that cos(-1) correctly, which I implemented as "The cosine to the power of -1".

推荐答案

立方体算法不会在球体上给出均匀分布 - 特别是靠近角投影的区域将具有最密集的点分布和靠近立方体的面中心最低.

The cube algorithm will not give an even distribution over the sphere - in particular the areas near the projections of the corners will have the densest distribution of points and near the centers of the faces of the cubes will be the lowest.

您可以直观地理解这一点,因为投影到底层球体上的立方体体积在靠近立方体中心的角落附近更大.事实上,一小块(投影在球体上的一个小圆圈上)的体积与从原点通过小圆的中心到它相交的球体上的点的向量大小的立方体.

You can understand this intuitively since the volume of cube projected onto the underlying sphere is larger near the corners that near the centers of the cubes faces. In fact, the volume of a small piece (that projects on a small circle on the sphere) is proportional to the cube of size of the vector from the origin through the center of the small circle to the point on the sphere that it intersects.

所以立方体面中心的相对体积(例如 (1,0,0))是 1,但对于角(例如 (1,1,1))是 sqrt(3) 的立方或 1.73 的立方,大约 5.2,所以几乎是密度的 5 倍!

So the relative volume on a cube face center (like (1,0,0)) is 1, but for a corner (e.g., (1,1,1)) is cube of sqrt(3) or 1.73 cubed, about 5.2, so almost 5 times denser!

spreadPoints() 函数可能做得更好,但我不确定.

The spreadPoints() function might do a better job, but I'm not sure.

JavaScript 中有几个错误 - 使用 pow(..,-1) 函数而不是 acos(),角度混淆,并且缺少用于 random() 调用的 Math 对象.,

There are a couple of errors in you JavaScript - the use of the pow(..,-1) function instead of acos(), mix ups on the angles and missing the Math object for the random() call.,

这里有类似但正确的 JavaScript 来执行 Wolfram 链接所说的:

Here is similar but correct JavaScript to do what the Wolfram links says:

/*
Returns a random point of a sphere, evenly distributed over the sphere.
The sphere is centered at (x0,y0,z0) with the passed in radius.
The returned point is returned as a three element array [x,y,z]. 
*/
function randomSpherePoint(x0,y0,z0,radius){
   var u = Math.random();
   var v = Math.random();
   var theta = 2 * Math.PI * u;
   var phi = Math.acos(2 * v - 1);
   var x = x0 + (radius * Math.sin(phi) * Math.cos(theta));
   var y = y0 + (radius * Math.sin(phi) * Math.sin(theta));
   var z = z0 + (radius * Math.cos(phi));
   return [x,y,z];
}

这篇关于给定球体上的随机点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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