如何在python中生成一个随机定向的高维圆?

How to generate a randomly oriented, high dimension circle in python?(如何在python中生成一个随机定向的高维圆?)
本文介绍了如何在python中生成一个随机定向的高维圆?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我想在 R^n 中生成一个随机定向的圆.我已经能够成功地在 n 球的表面上生成点.我读到你可以将它与平面相交并得到一个圆,但我不知道如何在 Python 中做到这一点.

I want to generate a randomly oriented circle in R^n. I have been able to successfully generate points on the surface of an n-sphere. I read that you can intersect it with a plane and get a circle, but I don't know how to do this in Python.

或者有没有其他方法可以在 Python 中生成它?

Or is there any other way to generate it in Python?

谢谢!

推荐答案

既然你已经知道如何在一个n-球面上生成一个随机点,那么只要生成两个这样的点,就叫它们P1P2.这些将确定圆所在的平面.

Since you already know how to generate a random point on the surface of an n-sphere, just generate two such points, call them P1 and P2. These will determine the plane in which the circle will lie.

我假设这两个点与原点的距离都是 1(如果您选择 1 作为 n 球体的半径,这将是真的).如果不是,则将每个点除以其长度.

I am assuming that both these points are a distance of 1 from the origin, (which will be true if you picked 1 as the radius of your n-sphere). If not, divide each point by its length.

现在我们想让 P2 垂直于 P1.这可以通过

Now we want to make P2 perpendicular to P1. This can be done by

P2 = P2 - dot(P1, P2) P1
P2 = P2 / || P2 ||

然后对于每个点,您可以生成 0 到 2pi 之间的随机角度.通过以下方式将此角度转换为圆上的一个点:

Then for each point, you can generate a random angle between 0 and 2pi. Convert this angle to a point on the circle by:

cos(angle) * P1 + sin(angle) * P2.

这篇关于如何在python中生成一个随机定向的高维圆?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

groupby multiple coords along a single dimension in xarray(在xarray中按单个维度的多个坐标分组)
Group by and Sum in Pandas without losing columns(Pandas中的GROUP BY AND SUM不丢失列)
Group by + New Column + Grab value former row based on conditionals(GROUP BY+新列+基于条件的前一行抓取值)
Groupby and interpolate in Pandas(PANDA中的Groupby算法和插值算法)
Pandas - Group Rows based on a column and replace NaN with non-null values(PANAS-基于列对行进行分组,并将NaN替换为非空值)
Grouping pandas DataFrame by 10 minute intervals(按10分钟间隔对 pandas 数据帧进行分组)