如何在Python中生成随机定向的高维圆? [英] How to generate a randomly oriented, high dimension circle in 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球面上生成随机点,只需生成两个这样的点,称他们为 P1
和 P2
。这些将决定圆圈所在的平面。
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之间的随机角度。通过以下方式将此角度转换为圆上的点:$ b
$ b
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中生成随机定向的高维圆?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!