I absolutely need to generate points uniformly and in Cartesian coordinates.

I have been looking into it for a few days now and cannot seem to find a good way to do it.

For the moment I did it on $\mathbb{R}^3$ which is equivalent to generate points of a circle on a plane. To do so, I projected the space on the 2-simplex (3D->2D) and I generated points of a circle using :

5 Answers
5

I'll answer using matrix vector notation, which generalizes the problem to multiple linear constraints. We wish to generate a point $\mathbf{x}$ which is in the intersection of a hypersphere and an affine space, which we can write like this:

The idea here is that the point $\mathbf{x}_0 + \mathbf{y}$ is the center of the intersection, and $\mathbf{z}/\|\mathbf{z}\|$ is uniformly distributed on the unit sphere of the null space of $\mathbf{A}$.

Note, we must have $r \ge \|\mathbf{y}\|$, otherwise the intersection is empty. Also, we assume $\mathbf{A}$ is full rank so that the pseudoinverse satisfies $\mathbf{A}^\dagger = \mathbf{A}^T(\mathbf{A A}^T)^{-1}$. In your case $\mathbf{A} = \mathbf{1}^T$ so $\mathbf{A}^\dagger = n^{-1}\mathbf{1}$.

You can always generate points uniformly on an n-sphere by sampling n+1 independent gaussians and then normalizing the resulting vector. So you ought to be able to do this by choosing n independent gaussians, projecting orthogonally to the plane, and then normalizing the vector.

Of course, you should do it w.r.t. a linear subspace if you want the normalization to preserve the subspace.
–
Ori Gurel-GurevichJun 19 '12 at 4:20

How would you normalize w.r.t a linear subspace ? I think here lies the point I am missing.
–
DavidJun 19 '12 at 8:07

You normalize after you project, and the normalized vector stays parallel to the subspace.
–
Douglas ZareJun 19 '12 at 8:14

I understood the principle but how to apply it (in my case) ? + another question comes to my mind, how do you manage the radius then ?
–
DavidJun 19 '12 at 8:22

(1) Generate a rotationally symmetric Gaussian distribution. (2) Project to the hyperplane through the origin parallel to your hyperplane. (3) Normalize to get a uniform distribution on a sphere in the hyperplane. (4) Translate back to your hyperplane. Which step is the problem? And if you need a sphere of a different radius you rescale in step (3).
–
Douglas ZareJun 19 '12 at 9:20

My problem is not about generating points on a n-sphere. The algorithm in the question you posted is the same as the one I exposed (that's what I meant by "this algorithm allows you to generate points on a n-sphere too"). The problem is more about "rotating" and "translating" a generated sphere to fit on/in the hyperplane.
–
DavidJun 19 '12 at 7:07