# 指定空间内，生成随机坐标点位_三维

0

“指定空间内，生成随机坐标点位”
(例如 在一个圆柱体内， 随机生成散点。最好是python实现， 其他语言也行)

3D 空间粒子效果

PS --- 有网友见过类似的博客吗，找了一圈没找到满意的

〆灬丶 | 老鸟四级 | 园豆：2307

2年前

0

https://stackoverflow.com/questions/66405264/generating-solid-spheres-in-python

〆灬丶 | 老鸟四级 |园豆：2307 | 2021-10-18 16:07

0

``````def random_ball(num_points, dimension, radius=1):
from numpy import random, linalg
# First generate random directions by normalizing the length of a
# vector of random-normal values (these distribute evenly on ball).
random_directions = random.normal(size=(dimension,num_points))
random_directions /= linalg.norm(random_directions, axis=0)
# Second generate a random radius with probability proportional to
# the surface area of a ball with a given radius.
# Return the list of random (direction & length) points.

"""
array([[-0.23396152, -0.67936419,  0.55005001],
[ 0.1691557 ,  0.03104764, -0.97471419],
[ 0.07458162,  0.61583175,  0.70946089],
[ 0.25455193, -0.55611147, -0.41187798],
[ 0.47061593,  0.24126442, -0.8053103 ],
[ 0.80211304, -0.10952756,  0.40626897],
[-0.21829698, -0.00210662,  0.2668299 ],
[-0.61603097,  0.06366497, -0.13768223],
[ 0.4580121 , -0.11881662, -0.44928392],
[-0.14152173,  0.0571525 , -0.51057342]])
"""

``````

您需要登录以后才能回答，未注册用户请先注册