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.
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.
Now we want to make P2
perpendicular to P1
. This can be done by
P2 = P2 - dot(P1, P2) P1
P2 = P2 / || P2 ||
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.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…