Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Batman Equation (Python)
# -*- coding: utf-8 -*-
Created on Fri Dec 16 09:30:30 2011
Python Batman Equation
@author: Trae Blain
from __future__ import division
import matplotlib.pyplot as plt
from numpy import sqrt #originally had from scipy import sqrt
from numpy import meshgrid
from numpy import arange
xs = arange(-7.25, 7.25, 0.01)
ys = arange(-5, 5, 0.01)
x, y = meshgrid(xs, ys)
eq1 = ((x/7)**2*sqrt(abs(abs(x)-3)/(abs(x)-3))+(y/3)**2*sqrt(abs(y+3/7*sqrt(33))/(y+3/7*sqrt(33)))-1)
eq2 = (abs(x/2)-((3*sqrt(33)-7)/112)*x**2-3+sqrt(1-(abs(abs(x)-2)-1)**2)-y)
eq3 = (9*sqrt(abs((abs(x)-1)*(abs(x)-.75))/((1-abs(x))*(abs(x)-.75)))-8*abs(x)-y)
eq4 = (3*abs(x)+.75*sqrt(abs((abs(x)-.75)*(abs(x)-.5))/((.75-abs(x))*(abs(x)-.5)))-y)
eq5 = (2.25*sqrt(abs((x-.5)*(x+.5))/((.5-x)*(.5+x)))-y)
eq6 = (6*sqrt(10)/7+(1.5-.5*abs(x))*sqrt(abs(abs(x)-1)/(abs(x)-1))-(6*sqrt(10)/14)*sqrt(4-(abs(x)-1)**2)-y)
#eq1 = ((x/7.0)**2.0*sqrt(abs(abs(x)-3.0)/(abs(x)-3.0))+(y/3.0)**2.0*sqrt(abs(y+3.0/7.0*sqrt(33.0))/(y+3.0/7.0*sqrt(33.0)))-1.0)
for f in [eq1,eq2,eq3,eq4,eq5,eq6]:
plt.contour(x, y, f, [0])
Copy link

azzassfa commented Dec 8, 2020

Awesome man ! what an epic piece of code. #bravo to you

2 observations though:

  1. works with scipy.sqrt rather than numpy.sqrt (could be my installations of python)
  2. the plot has some additional lines that need to be removed

but again AWESOME work !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment