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

2022-01-14 00:00:00 python numpy geometry math

问题描述

我想在 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.

相关文章