Skip to content

Instantly share code, notes, and snippets.

@senderle
Created July 28, 2018 19:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save senderle/a7cf069a97ac268fc5485ec3ddca1242 to your computer and use it in GitHub Desktop.
Save senderle/a7cf069a97ac268fc5485ec3ddca1242 to your computer and use it in GitHub Desktop.
Projecting the 3-simplex onto the sphere, with planes of projection.
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
fig = plt.figure(figsize=(21, 18))
ax = fig.add_subplot(111, projection='3d')
u_c = np.linspace(0, np.pi / 2, 100)
v_c = np.linspace(0, np.pi / 2, 100)
x_c = 1 * np.outer(np.cos(u_c),
np.sin(v_c))
y_c = 1 * np.outer(np.sin(u_c),
np.sin(v_c))
z_c = 1 * np.outer(np.ones(np.size(u_c)),
np.cos(v_c))
ax.plot_surface(x_c, y_c, z_c,
rstride=5, cstride=5,
color='pink', linewidth=0.2, alpha=0.5, antialiased=True)
u = np.linspace(0, 1, 100)
v = np.linspace(0, 1, 100)
x_s = 1 * np.outer(1 - u,
v)
y_s = 1 * np.outer(u,
v)
z_s = 1 * np.outer(np.ones(np.size(u)),
1 - v)
ax.plot_surface(x_s, y_s, z_s,
rstride=5, cstride=5,
color='darkblue', linewidth=1, alpha=0.8, antialiased=True)
z_l1 = 0.466666
y_l1 = u * 0.533333
x_l1 = (1 - u) * 0.533333
norms1 = (z_l1 * z_l1 +
y_l1 * y_l1 +
x_l1 * x_l1) ** 0.5
ax.plot(x_l1, y_l1, z_l1, color='lightblue',
linewidth=2)
ax.plot(x_l1 / norms1, y_l1 / norms1,
z_l1 / norms1, color='darkblue',
linewidth=3)
z_l2 = 0.2
y_l2 = u * 0.8
x_l2 = (1 - u) * 0.8
norms2 = (z_l2 * z_l2 +
y_l2 * y_l2 +
x_l2 * x_l2) ** 0.5
ax.plot(x_l2, y_l2, z_l2, color='lightblue',
linewidth=2)
ax.plot(x_l2 / norms2, y_l2 / norms2,
z_l2 / norms2, color='darkblue',
linewidth=3)
r = np.linspace(0, 1, 100)[None, :]
r_norms1 = r / norms1[:, None]
x_p1 = x_l1[:, None] * r_norms1
y_p1 = y_l1[:, None] * r_norms1
z_p1 = z_l1 * np.ones_like(y_l1)[:, None] * r_norms1
ax.plot_surface(x_p1, y_p1, z_p1,
rstride=10, cstride=10,
color='lightblue', linewidth=0.2,
alpha=0.25, antialiased=True)
r_norms2= r / norms2[:, None]
x_p2 = x_l2[:, None] * r_norms2
y_p2 = y_l2[:, None] * r_norms2
z_p2 = z_l2 * np.ones_like(y_l2)[:, None] * r_norms2
ax.plot_surface(x_p2, y_p2, z_p2,
rstride=10, cstride=10,
color='lightblue', linewidth=0.2,
alpha=0.25, antialiased=True)
ax.view_init(elev = 18, azim = -45)
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment