Uniform generation of u and v does not necessarily lead to uniform sampling from the surface of the torus. An additional step is needed.
J. F. Williamson, "Random selection of points distributed over curved surfaces," Physics in Medicine & Biology 32 (10), 1987, describes a general method for selecting a uniformly random point on a curved surface. This is an acceptance / rejection method that accepts or rejects each candidate point depending on its stretching coefficient (gradient norm). To use this method, you need to know two things about the surface, namely:
g(point) , the norm of the gradient (the "coefficient of expansion") at each point on the surface, andgmax , the maximum value of g for the entire surface.
For a three-dimensional torus with parameterization, which you gmax in your question, g and gmax as follows:
g(u, v) = a * (c + cos(v) * a) .gmax = a * (a + c) .
The algorithm for generating a uniform random point on the surface of a three-dimensional torus with torus radius c and tube radius a will be as follows (where RNDEXCRANGE(x,y) returns a number in [x,y) and RNDRANGE(x,y) returns a number in [x,y] ):
// Maximum stretch factor for torus gmax = a * (a + c) while true u = RNDEXCRANGE(0, pi * 2) v = RNDEXCRANGE(0, pi * 2) x = cos(u)*(c+cos(v)*a) y = sin(u)*(c+cos(v)*a) z = sin(v)*a // Norm of gradient (stretch factor) g = a*abs(c+cos(v)*a) if g >= RNDRANGE(0, gmax) // Accept the point return [x, y, z] end end
If you have n-dimensional formulas for generating a torus, a similar approach can be used to generate uniform random points on this torus (accept a candidate point if the gradient norm is equal to or exceeds a random number in [0, gmax ), where gmax maximum gradient norm )
source share