eigenvectors / utils.py
sharmaanupam's picture
Added Batman logo, transformation types and updated description (#2)
c1ab7e8
import numpy as np
import matplotlib.pyplot as plt
def getSquareY(x):
if x==-1 or x == 1:
return 0
else:
return 1
getSquareYVectorised = np.vectorize(getSquareY)
def getCircle(x):
return np.sqrt(1 - np.square(x))
def transform(x,y,t):
points = np.array([x, y])
result = t @ points
return result[0,:], result[1,:]
def plotGridLines(xlim,ylim,t,color,label,linewidth):
for i in range(xlim[0]-20,xlim[1]+21):
x = [i,i]
y = [ylim[0]-20,ylim[1]+20]
x,y = transform(x,y,t)
if i == xlim[0]-20:
plt.plot(x,y, color=color,linestyle='dashed',linewidth=linewidth,label=label)
else:
plt.plot(x,y, color=color,linestyle='dashed',linewidth=linewidth)
for i in range(ylim[0]-20,ylim[1]+21):
y = [i,i]
x = [xlim[0]-20,xlim[1]+20]
x,y = transform(x,y,t)
plt.plot(x,y, color=color,linestyle='dashed',linewidth=linewidth)
def discriminant(t):
return t[0,0]**2 - 2*t[1,1]*t[0,0] + t[1,1]**2 + 4*t[0,1]*t[1,0]
def getBatman(s=2):
X = []
Y = []
# lower
x = np.linspace(-4, 4, 1600)
y = np.zeros((0))
for px in x:
y = np.append(y,abs(px/2)- 0.09137*px**2 + np.sqrt(1-(abs(abs(px)-2)-1)**2) -3)
X.append(x/s)
Y.append(y/s)
# lower left
x = np.linspace(-7., -4, 300)
y = np.zeros((0))
for px in x:
y = np.append(y, -3*np.sqrt(-(px/7)**2+1))
X.append(x/s)
Y.append(y/s)
# lower right
x = np.linspace(4, 7, 300)
y = np.zeros((0))
for px in x:
y = np.append(y, -3*np.sqrt(-(px/7)**2+1))
X.append(x/s)
Y.append(y/s)
# top left
x = np.linspace(-7, -2.95, 300)
y = np.zeros((0))
for px in x:
y = np.append(y, 3*np.sqrt(-(px/7)**2+1))
X.append(x/s)
Y.append(y/s)
# top right
x = np.linspace(2.95, 7, 300)
y = np.zeros((0))
for px in x:
y = np.append(y, 3*np.sqrt(-(px/7)**2+1))
X.append(x/s)
Y.append(y/s)
# left ear left
x = np.linspace(-1, -.77, 2)
y = np.zeros((0))
for px in x:
y = np.append(y, 9-8*abs(px))
X.append(x/s)
Y.append(y/s)
# right ear right
x = np.linspace(.77, 1, 2)
y = np.zeros((0))
for px in x:
y = np.append(y, 9-8*abs(px))
X.append(x/s)
Y.append(y/s)
# mid
x = np.linspace(-.43, .43, 100)
y = np.zeros((0))
for px in x:
y = np.append(y,2)
X.append(x/s)
Y.append(y/s)
x = np.linspace(-2.91, -1, 100)
y = np.zeros((0))
for px in x:
y = np.append(y, 1.5 - .5*abs(px) - 1.89736*(np.sqrt(3-px**2+2*abs(px))-2) )
X.append(x/s)
Y.append(y/s)
x = np.linspace(1, 2.91, 100)
y = np.zeros((0))
for px in x:
y = np.append(y, 1.5 - .5*abs(px) - 1.89736*(np.sqrt(3-px**2+2*abs(px))-2) )
X.append(x/s)
Y.append(y/s)
x = np.linspace(-.7,-.43, 10)
y = np.zeros((0))
for px in x:
y = np.append(y, 3*abs(px)+.75)
X.append(x/s)
Y.append(y/s)
x = np.linspace(.43, .7, 10)
y = np.zeros((0))
for px in x:
y = np.append(y, 3*abs(px)+.75)
X.append(x/s)
Y.append(y/s)
return X, Y