[OC] Pi-Digit Path with Intersection Density and Resultant Vector

Made this out of curiousity but it probably doesn't mean much. In this visualization, each digit d of π (from 0 to 9) is mapped to a complex phase e^{(i2\pi d)/10}. The cumulative sum of these phases are taken over a large number of digits (1 million for this plot). The color map shows how frequently the path intersects each region. The green line is the resultant vector from the origin to the final point of the walk.

Here is the code for anyone wanting to recreate this and if you want to add more to it:

import numpy as np

import matplotlib.pyplot as plt

from mpmath import mp

from scipy.stats import gaussian_kde

from tqdm import tqdm # Make sure to install tqdm via \pip install tqdm``

# Set precision (adjust mp.dps as needed)

mp.dps = 1000000 # Increase for more digits; higher precision may slow computation.

pi_digits_str = str(mp.pi)[2:] # Skip the "3." of π (e.g., from 3.1415...)

# Convert the digits into integers with a progress bar

digits = np.array([int(d) for d in tqdm(pi_digits_str, desc="Converting digits")])

# Map digits to complex exponentials using Euler's formula

vectors = np.exp(1j * 2 * np.pi * digits / 10)

# Compute the cumulative sum (the π-digit path) with a progress bar

path = np.empty(len(vectors), dtype=complex)

current = 0 + 0j

for i, v in tqdm(enumerate(vectors), total=len(vectors), desc="Computing cumulative sum"):

current += v

path[i] = current

# Precompute a density estimate over the path points using Gaussian KDE

xy = np.vstack([path.real, path.imag])

density = gaussian_kde(xy)(xy)

# Set up the figure with fixed dimensions

fig, ax = plt.subplots(figsize=(10, 10))

ax.set_title('$\\pi$-Digit Path with Intersection Density and Resultant Vector')

ax.set_xlabel('Real')

ax.set_ylabel('Imaginary')

ax.grid(True, alpha=0.5)

# Plot the density background as a scatter plot (small points colored by density)

density_scatter = ax.scatter(path.real, path.imag, c=density, cmap='jet',

s=1, alpha=0.5, zorder=0)

plt.colorbar(density_scatter, ax=ax, label='Intersection Density')

# Plot the π-digit path as a thin black line

ax.plot(path.real, path.imag, lw=0.01, color='black', label='$\\pi$ Digit Path')

# Calculate and plot the resultant vector (last point in the cumulative sum)

R = path[-1]

ax.plot([0, R.real], [0, R.imag], color='green', lw=1.5, label='Resultant Vector')

# Adjust axis limits to encompass the full path and the resultant vector

all_path_x = np.concatenate((path.real, [0, R.real]))

all_path_y = np.concatenate((path.imag, [0, R.imag]))

margin = 1

ax.set_xlim(all_path_x.min() - margin, all_path_x.max() + margin)

ax.set_ylim(all_path_y.min() - margin, all_path_y.max() + margin)

ax.legend()

plt.show()

Made this out of curiousity but it probably doesn't mean much. In this visualization, each digit d of π (from 0 to 9) is mapped to a complex phase e^{(i2\pi d)/10}. The cumulative sum of these phases are taken over a large number of digits (1 million for this plot). The color map shows how frequently the path intersects each region. The green line is the resultant vector from the origin to the final point of the walk.

Here is the code for anyone wanting to recreate this and if you want to add more to it:

import numpy as np

import matplotlib.pyplot as plt

from mpmath import mp

from scipy.stats import gaussian_kde

from tqdm import tqdm # Make sure to install tqdm via \pip install tqdm``

# Set precision (adjust mp.dps as needed)

mp.dps = 1000000 # Increase for more digits; higher precision may slow computation.

pi_digits_str = str(mp.pi)[2:] # Skip the "3." of π (e.g., from 3.1415...)

# Convert the digits into integers with a progress bar

digits = np.array([int(d) for d in tqdm(pi_digits_str, desc="Converting digits")])

# Map digits to complex exponentials using Euler's formula

vectors = np.exp(1j * 2 * np.pi * digits / 10)

# Compute the cumulative sum (the π-digit path) with a progress bar

path = np.empty(len(vectors), dtype=complex)

current = 0 + 0j

for i, v in tqdm(enumerate(vectors), total=len(vectors), desc="Computing cumulative sum"):

current += v

path[i] = current

# Precompute a density estimate over the path points using Gaussian KDE

xy = np.vstack([path.real, path.imag])

density = gaussian_kde(xy)(xy)

# Set up the figure with fixed dimensions

fig, ax = plt.subplots(figsize=(10, 10))

ax.set_title('$\\pi$-Digit Path with Intersection Density and Resultant Vector')

ax.set_xlabel('Real')

ax.set_ylabel('Imaginary')

ax.grid(True, alpha=0.5)

# Plot the density background as a scatter plot (small points colored by density)

density_scatter = ax.scatter(path.real, path.imag, c=density, cmap='jet',

s=1, alpha=0.5, zorder=0)

plt.colorbar(density_scatter, ax=ax, label='Intersection Density')

# Plot the π-digit path as a thin black line

ax.plot(path.real, path.imag, lw=0.01, color='black', label='$\\pi$ Digit Path')

# Calculate and plot the resultant vector (last point in the cumulative sum)

R = path[-1]

ax.plot([0, R.real], [0, R.imag], color='green', lw=1.5, label='Resultant Vector')

# Adjust axis limits to encompass the full path and the resultant vector

all_path_x = np.concatenate((path.real, [0, R.real]))

all_path_y = np.concatenate((path.imag, [0, R.imag]))

margin = 1

ax.set_xlim(all_path_x.min() - margin, all_path_x.max() + margin)

ax.set_ylim(all_path_y.min() - margin, all_path_y.max() + margin)

ax.legend()

plt.show()