如何使用Python从3-D椭球体中生成随机的点样本? [英] How to generate a random sample of points from a 3-D ellipsoid using Python?

查看:181
本文介绍了如何使用Python从3-D椭球体中生成随机的点样本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从3-D椭圆形均匀采样大约1000个点.有什么编码方法可以使我们从椭球方程开始获取点?

I am trying to sample around 1000 points from a 3-D ellipsoid, uniformly. Is there some way to code it such that we can get points starting from the equation of the ellipsoid?

我要在椭球表面上点.

推荐答案

此处是一种通用函数,用于选择球形,椭球形或具有a,b和c参数的任何三轴椭球表面上的随机点.请注意,直接生成角度将不会提供均匀的分布,并且会导致沿z方向的点过多.相反,phi是作为随机生成的cos(phi)的逆获得的.

Here is a generic function to pick a random point on a surface of a sphere, spheroid or any triaxial ellipsoid with a, b and c parameters. Note that generating angles directly will not provide uniform distribution and will cause excessive population of points along z direction. Instead, phi is obtained as an inverse of randomly generated cos(phi).

    import numpy as np
    def random_point_ellipsoid(a,b,c):
        u = np.random.rand()
        v = np.random.rand()
        theta = u * 2.0 * np.pi
        phi = np.arccos(2.0 * v - 1.0)
        sinTheta = np.sin(theta);
        cosTheta = np.cos(theta);
        sinPhi = np.sin(phi);
        cosPhi = np.cos(phi);
        rx = a * sinPhi * cosTheta;
        ry = b * sinPhi * sinTheta;
        rz = c * cosPhi;
        return rx, ry, rz

此函数从此帖子中采用: https://karthikkaranth.me/blog/generating-random-points-in-a-sphere/

This function is adopted from this post: https://karthikkaranth.me/blog/generating-random-points-in-a-sphere/

这篇关于如何使用Python从3-D椭球体中生成随机的点样本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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