A noise sphere maps a sequence of uniformly-distributed random numbers to spherical coordinate triples.
This is useful for visually detecting any unexpected correlations in the random number sequence
or to detect unexpected structure indicating correlations between triples.
When such structure is present, numbers may not be truly random.
Workflow:
Step 1) generate an array of RandomNumbers[]
randomNumbers[] = GenerateRandomNumbers(maxPts);
Step 2) take 3 numbers into an array PT[n, n+1, n+2] rotating every point (so each point becomes x, y, z)
let PT = [0, 0, 0];
for (var i = 0; i < (randomNumbers.length);) {
for (var j = 0; j < 3; j++) {
PT[j] = randomNumbers[i];
i++;
}
... more stuff ...
}
Step 3) convert the 3 points from PT[p0, p1, p2] to Polar(r, theta, phi) coordinates
A mapping of random number triples to points in spherical coordinates according to:
Noise Sphere https://mathworld.wolfram.com/NoiseSphere.html
θ = 2 π X n
φ = π X n+1
ρ = Math.sqrt( X x+2 )
let polar = { r: 0.0, theta: 0.0, phi: 0.0 };
polar.phi = 2 * Math.PI * PT[n]; /* p0 */
polar.theta = Math.PI * PT[(n + 1) % 3]; /* p1 */
polar.r = Math.sqrt(PT[(n + 2) % 3]); /* p2 */
/* rotate n: (0,1,2) => (1,2,0) => (2,0,1) => (0,1,2) */
n = (n + 1) % 3;
Step 4) convert Polar(r, theta, phi) to Cartesian P(x,y,z)
Spherical Coordinates: https://mathworld.wolfram.com/SphericalCoordinates.html
Coordinates: spherical (r,theta,phi) are related to the Cartesian (x,y,z) by:
x = r * cos (θ) * sin (φ)
y = r * sin (θ) * sin (φ)
z = r * cos (φ)
x = r * cos(theta) * sin(phi)
y = r * sin(theta) * sin(phi)
z = r * cos(phi)
Step 5) plot all points on canvas using Cartesian(x,y)
putpixel(MidA + ProjectPoint(C.x), MidY - ProjectPoint(C.y), C.Color);
Rotate n: (0,1,2) => (1,2,0) => (2,0,1) => (0,1,2)
-------------- 0 1 2 0
(n) => 0 1 2 0
(n + 1) % 3 => 1 2 0 1
(n + 2) % 3 => 2 0 1 2
---------------------------------------------------------------------------------------------------
n: 0
(n) => 0
(n + 1) % 3 => 1
(n + 2) % 3 => 2
n: 1
(n) => 1
(n + 1) % 3 => 2
(n + 2) % 3 => 0
n: 2
(n) => 2
(n + 1) % 3 => 0
(n + 2) % 3 => 1
n: 3
(n) => 0
(n + 1) % 3 => 1
(n + 2) % 3 => 2