Skip to content

Instantly share code, notes, and snippets.

@bhawkins
Created March 15, 2013 03:49
Show Gist options
  • Save bhawkins/5167350 to your computer and use it in GitHub Desktop.
Save bhawkins/5167350 to your computer and use it in GitHub Desktop.
A python script to plot the mysterious equation found in some Israeli graffiti.
#!/usr/bin/env python
import numpy as np
import pylab as p
from mpl_toolkits.mplot3d import Axes3D
n = 201
R = 1.0
gamma = 1
# The surface has radial symmetry, so use a polar grid instead of a rectangular
# one. Also avoid computing imaginary values. The radius of the circle in
# the z=0 plane is (R+gamma).
xmax = R + gamma
r = np.linspace (0, xmax, n)
th = np.linspace (0, 2*np.pi, n)
RAD, TH = np.meshgrid (r, th)
X = RAD * np.cos (TH)
Y = RAD * np.sin (TH)
# Compute both halves of the surface z=f(x,y).
Z1 = np.sqrt (gamma**2 - (R - np.sqrt (X**2 + Y**2))**2)
Z2 = -Z1
fig = p.figure()
ax = fig.add_subplot (111, projection='3d')
ax.plot_surface (X, Y, Z1, color='white')
ax.plot_surface (X, Y, Z2, color='white')
ax.set_title (r'$\left( R - \sqrt{x^2 + y^2} \right)^2 + z^2 = \gamma^2$')
p.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment