Skip to content

Instantly share code, notes, and snippets.

@senderle
Created July 28, 2018 12:12
Show Gist options
  • Save senderle/0ff0ded1a74c9040785800ff84f9dc3c to your computer and use it in GitHub Desktop.
Save senderle/0ff0ded1a74c9040785800ff84f9dc3c to your computer and use it in GitHub Desktop.
Projecting the 3-simplex onto the sphere.
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.5, alpha=0.75, 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=1.0, antialiased=True)
#z_l1 = u * 0.4
#y_l1 = 0.2 + u * 0.4
#x_l1 = 0.8 * (1 - u)
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=2)
#z_l2 = 0.2 + u * 0.4
#y_l2 = u * 0.4
#x_l2 = 0.8 * (1 - u)
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=2)
ax.view_init(elev = 36, azim = 36)
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment