"""
Examples of surfaces with constant Gaussian curvature.
Created with Matplotlib 3.4.3.
"""
import numpy as np
from numpy import pi, cos, sin, sqrt, outer, ones, sinh, cosh
from scipy.integrate import quad
import matplotlib.pyplot as plt
fig = plt.figure(figsize=(10, 10))
ax = fig.add_subplot(111, projection='3d')
u = np.linspace(0, 2 * pi, 100)
v = np.linspace(0, pi, 100)
one_v = ones(100)
# Sphere
x1 = 10 * outer(cos(u), sin(v))
y1 = 10 * outer(sin(u), sin(v)) + 17
z1 = 10 * outer(one_v, cos(v))
ax.plot_surface(x1, y1, z1, rstride=5, cstride=5, cmap='Spectral',
linewidth=0.5, edgecolors="#3c3c3c")
# Cylinder
x2 = 6 * outer(cos(u), one_v)
y2 = 6 * outer(sin(u), one_v)
z2 = 20 * outer(one_v, v/pi - 0.5)
ax.plot_surface(x2, y2, z2, rstride=5, cstride=5, cmap='Spectral',
linewidth=0.5, edgecolors="#3c3c3c")
# Negative Gaussian curvature
u = np.linspace(-pi, pi, 100)
v = np.linspace(-1.4436, 1.4436, 100)
aux = np.zeros_like(v)
for cont, val in enumerate(v):
aux[cont] = quad(lambda t: sqrt(1 - 0.25*sinh(t)**2), 0, val)[0]
x3 = 4 * outer(cos(u), cosh(v))
y3 = 4 * outer(sin(u), cosh(v)) - 16
z3 = 8 * outer(one_v, aux)
ax.plot_surface(x3, y3, z3, rstride=5, cstride=5, cmap='Spectral',
linewidth=0.5, edgecolors="#3c3c3c")
# Fix aspect ratio and axes details
ax.set_box_aspect((np.ptp(np.column_stack((x1, x2, x3))),
np.ptp(np.column_stack((y1, y2, y3))),
np.ptp(np.column_stack((z1, z2, z3)))))
ax.view_init(elev=35, azim=-45)
plt.axis('off')
plt.savefig('Constant gaussian curvature.svg', transparent=True)
plt.show()