创建比给定长度L更远的N个随机点(python,N = 200) [英] create N random points all more distant than given length L (python and N = 200)

查看:51
本文介绍了创建比给定长度L更远的N个随机点(python,N = 200)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

类似的问题:
生成N个随机点,它们之间具有一定的预定距离

Similar questions:
Generating N random points with certain predefined distance between them

在R中选择n个最远的点

但是它们要么在matlab中,要么没有完成所需的任务.

But they are either in matlab or does not fullfill the required task.

我必须在一个长度为 任何两点之间的距离都大于delta.

I have to create N number of points inside a box of length that the distance between any two points is larger than delta.

例如: 假设我在x,y,z轴上有一个长10埃的盒子.
我想在此框内放置200个随机点,以使最小距离 任何两个点之间的距离都大于3埃.

For example: Let's say I have a box of length 10 Angstrom on x,y,z axis.
I want to have 200 random points inside this box so that minimum distance between any two points is larger than 3 Angstrom.

尝试:

#!python
# -*- coding: utf-8 -*-#
import numpy as np
np.random.seed(100)
np.set_printoptions(2)

box_length = 10
d = box_length
threshold = 6
num_points = 5
x1, y1, z1 = np.random.random(num_points)* box_length, np.random.random(num_points)* box_length, np.random.random(num_points)* box_length
x2, y2, z2 = np.random.random(num_points)* box_length, np.random.random(num_points)* box_length, np.random.random(num_points)* box_length

# print(len(x1))

# just for checking make ponts integers
for i in range(len(x1)):
    x1[i] = int(x1[i])
    x2[i] = int(x2[i])
    y1[i] = int(y1[i])
    y2[i] = int(y2[i])
    z1[i] = int(z1[i])
    z2[i] = int(z2[i])


print(x1)
print(y1)
print(z1)
print("\n")

pt1_lst = []
pt2_lst = []
for i in range(len(x1)):
    a, b, c    = x1[i], y1[i], z1[i]
    a2, b2, c2 = x2[i], y2[i], z2[i]
    dist2      = (a-a2)**2 + (b-b2)**2 + (c-c2)**2

    print("\n")
    print(a,b,c)
    print(a2,b2,c2)
    print(dist2)

    if dist2 > threshold**2:
        pt1 = (a,b,c)
        pt2 = (a2,b2,c2)
        pt1_lst.append(pt1)
        pt2_lst.append(pt2)



print("points")
print(pt1_lst)
print(pt2_lst)

代码问题: 该代码比较点1和点2之间的点,但不对点1和点2内部进行比较.

Problem on Code: This code compares points from points1 to points2 but does not compare within itself inside points1 and points2.

可能有更好的算法可以解决此问题,因此对那些问题不屑一顾 提出了解决问题的好主意的人.

There might be better algorithms to solve this problem and hats off to those guys who come with the brilliant idea to solve the problem.

谢谢.

PS : 我做了一些研究,试图找到相关的链接,但是无法解决 问题. 仍然有一些相关链接:

PS: I did some research and try to find related links, however was unable to solve the problem. Still some related links are:

更新 ::

我在下面尝试了Stefans的代码,它适用于N = 10,但是我尝试了N = 200,并且它使用的时间非常长(我在10分钟后停止了代码).

I attempted Stefans' code below, It works for N= 10 but I tried it for N = 200 and it is using extremely large time ( I stopped the code after 10 minutes).

有什么有效的方法吗?

我们将不胜感激!

从节点n开始的所有长度为L的路径都使用python
使用Python在定义的矩形内创建随机点

推荐答案

这种分布的通用名称是泊松球采样.有一个已知的O(n)可以执行此操作-请在此处进行检查

Common name for such distribution is Poisson spheres sampling. There is known O(n) which does this - please check here

这篇关于创建比给定长度L更远的N个随机点(python,N = 200)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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