如何在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中生成一个随机定向的高维圆?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:如何在python中生成一个随机定向的高维圆?

基础教程推荐