在球面上均匀分布n个点
问题描述
我需要一种算法,它可以为我在一个球体周围提供 N 个点(可能小于 20 个)的位置,并将它们模糊地分散开来.不需要完美",但我只需要它,所以它们都不会聚集在一起.
I need an algorithm that can give me positions around a sphere for N points (less than 20, probably) that vaguely spreads them out. There's no need for "perfection", but I just need it so none of them are bunched together.
- 这个问题提供了很好的代码,但我找不到办法做到这一点统一,因为这似乎是 100% 随机的.
- 这篇博文推荐有两种方法允许输入球体上的点数,但 Saff and Kuijlaars 算法完全是我可以转录的伪代码,而 代码示例 我发现包含node[k]",我看不到它的解释并破坏了这种可能性.第二个博客示例是黄金分割螺旋,它给了我奇怪的、成束的结果,没有明确的方法来定义一个恒定的半径.
- 这个算法来自 这个问题 似乎可行,但我无法将该页面上的内容拼凑成伪代码或任何内容.李>
- This question provided good code, but I couldn't find a way to make this uniform, as this seemed 100% randomized.
- This blog post recommended had two ways allowing input of number of points on the sphere, but the Saff and Kuijlaars algorithm is exactly in psuedocode I could transcribe, and the code example I found contained "node[k]", which I couldn't see explained and ruined that possibility. The second blog example was the Golden Section Spiral, which gave me strange, bunched up results, with no clear way to define a constant radius.
- This algorithm from this question seems like it could possibly work, but I can't piece together what's on that page into psuedocode or anything.
我遇到的其他一些问题主题谈到了随机均匀分布,这增加了我不关心的复杂程度.很抱歉,这是一个如此愚蠢的问题,但我想表明我真的很努力,但仍然没有完成.
A few other question threads I came across spoke of randomized uniform distribution, which adds a level of complexity I'm not concerned about. I apologize that this is such a silly question, but I wanted to show that I've truly looked hard and still come up short.
所以,我正在寻找的是简单的伪代码,用于将 N 个点均匀分布在一个单位球体周围,以球坐标或笛卡尔坐标返回.如果它甚至可以稍微随机分布(想象一下围绕恒星的行星,分布均匀,但有余地),那就更好了.
So, what I'm looking for is simple pseudocode to evenly distribute N points around a unit sphere, that either returns in spherical or Cartesian coordinates. Even better if it can even distribute with a bit of randomization (think planets around a star, decently spread out, but with room for leeway).
解决方案
在 这个示例代码 node[k]
只是第k个节点.您正在生成一个数组 N 个点,而 node[k]
是第 k 个(从 0 到 N-1).如果这就是让您感到困惑的全部,希望您现在可以使用它.
In this example code node[k]
is just the kth node. You are generating an array N points and node[k]
is the kth (from 0 to N-1). If that is all that is confusing you, hopefully you can use that now.
(换句话说,k
是在代码片段开始之前定义的大小为 N 的数组,其中包含点列表).
(in other words, k
is an array of size N that is defined before the code fragment starts, and which contains a list of the points).
或者,以此处的另一个答案为基础(并使用 Python):
Alternatively, building on the other answer here (and using Python):
> cat ll.py
from math import asin
nx = 4; ny = 5
for x in range(nx):
lon = 360 * ((x+0.5) / nx)
for y in range(ny):
midpt = (y+0.5) / ny
lat = 180 * asin(2*((y+0.5)/ny-0.5))
print lon,lat
> python2.7 ll.py
45.0 -166.91313924
45.0 -74.0730322921
45.0 0.0
45.0 74.0730322921
45.0 166.91313924
135.0 -166.91313924
135.0 -74.0730322921
135.0 0.0
135.0 74.0730322921
135.0 166.91313924
225.0 -166.91313924
225.0 -74.0730322921
225.0 0.0
225.0 74.0730322921
225.0 166.91313924
315.0 -166.91313924
315.0 -74.0730322921
315.0 0.0
315.0 74.0730322921
315.0 166.91313924
如果您绘制它,您会发现两极附近的垂直间距较大,因此每个点都位于大约相同的总区域空间中(靠近两极的空间较小)水平",所以它给出更多的垂直").
If you plot that, you'll see that the vertical spacing is larger near the poles so that each point is situated in about the same total area of space (near the poles there's less space "horizontally", so it gives more "vertically").
这与与邻居距离大致相同的所有点不同(我认为您的链接正在谈论这一点),但它可能足以满足您的需求,并改进了简单地制作统一的纬度/lon 网格.
This isn't the same as all points having about the same distance to their neighbours (which is what I think your links are talking about), but it may be sufficient for what you want and improves on simply making a uniform lat/lon grid.
相关文章