在球体上均匀分布 n 个点 [英] Evenly distributing n points on a sphere

查看:44
本文介绍了在球体上均匀分布 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 和 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.

这篇关于在球体上均匀分布 n 个点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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