当前位置: 首页 > article >正文

均匀球形分布的随机三维单位向量

生成具有均匀球形分布的随机三维单位向量[参考]

import numpy as np
import matplotlib.pyplot as plt
def random_three_vector():
    """
    Generates a random 3D unit vector (direction) with a uniform spherical distribution
    Algo from http://stackoverflow.com/questions/5408276/python-uniform-spherical-distribution
    :return:
    """
    phi = np.random.uniform(0,np.pi*2)
    costheta = np.random.uniform(-1,1)

    theta = np.arccos( costheta )
    x = np.sin( theta) * np.cos( phi )
    y = np.sin( theta) * np.sin( phi )
    z = np.cos( theta )
    return (x,y,z)

# Example IPython code to test the uniformity of the distribution
from pylab import scatter
threetups = []
for _ in range(1000):
    threetups.append(random_three_vector())
x,y,z = zip(*threetups)

plt.scatter(x, y)
plt.title("Distribution of Random 3D Unit Vectors")
plt.xlabel("X-axis")
plt.ylabel("Y-axis")
plt.show()

result:


http://www.kler.cn/a/145128.html

相关文章:

  • Ubuntu 18.04安装Emacs 26.2问题解决
  • SpringBoot整合Swagger UI 用于提供接口可视化界面
  • 灰色预测模型
  • 360大数据面试题及参考答案
  • C++:多继承习题5
  • shell脚本
  • 【nlp】2.8 注意力机制拓展
  • TCP/IP协议、三次握手、四次挥手
  • 【开源项目】C#.NET 扩展库 -- Com.Gitusme.Net.Extensiones.Core
  • 为什么程序员最应该学习的是运营与销售,而不是技术?
  • AMESim与MATLAB联合仿真demo
  • 数据结构与算法之二叉树: LeetCode 226. 翻转二叉树 (Typescript版)
  • 24. 深度学习进阶 - 矩阵运算的维度和激活函数
  • C#,《小白学程序》第十一课:双向链表(Linked-List)其二,链表的插入与删除的方法(函数)与代码
  • CocosCreator 面试题(十五)Cocos Creator如何内置protobuf JS版本?
  • Spring Boot 3.2.0 现已推出
  • 基于springboot实现私人健身与教练预约管理系统项目【项目源码+论文说明】计算机毕业设计
  • postgresql从入门到精通 - 第35讲:中间件PgBouncer部署|PostgreSQL教程
  • Re54:读论文 How Context Affects Language Models‘ Factual Predictions
  • 梯度详解与优化实战
  • Android 一键屏锁的实现
  • RabbitMQ之发送者(生产者)可靠性
  • Linux常用命令——bg命令
  • MyBatis的功能架构,MyBatis的框架架构设计,Mybatis都有哪些Executor执行器,Mybatis中如何指定使用哪一种Executor执行器
  • ctfshow刷题web入门--1--ljcsd
  • 【版本管理 | Git】Git rebase 命令最佳实践!确定不来看看?