在给定的点python周围生成点的随机簇 [英] generate a random cluster of points around a given point python
问题描述
我的问题是,是否有任何内置在python库中的东西可以让我围绕给定的x,y,z点生成一个随机的3D点簇(x,y,z)?
My question is if there is something built into any of the python libraries that would allow me to generate a random cluster of 3D points (x,y,z) around a given x,y,z point?
我似乎找不到与此类似的任何内容,但我是 python 的新手,所以我不确定它是否非常明显,或者我必须尝试通过使用给定点的特定范围内的随机数手动执行此操作
I can't seem to find anything similar to this but I am new to python so I'm not sure if its blindingly obvious or I have to try do it manually by using random numbers within a certain range of the given point
推荐答案
只需使用 random
库;
这将使您的点在原始点之间均匀分布.
This will give you poitns uniformly spaced aroudn the original point.
import random
source = [x,y,z]
deviationFromPoint = 10
for _ in range(numberOfAdditionalPoints):
newCoords = [source[i] + random.random() * deviationFromPoint for i in range(3)]
newPoint = Point(newCoords) # Or whatever constructor you have for your points.
如果要使用其他发行版,则jsut使用其他发行版,请查看 random
If you want a different distribution, jsut use a different distribution, look in the documentation of random
这篇关于在给定的点python周围生成点的随机簇的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!