import numpy as np import matplotlib.pyplot as plt import cmath import math def initDraw(Xmin, Xmax, Ymin, Ymax): #plt.axis('equal') plt.axis([Xmin, Xmax, Ymin, Ymax]) plt.grid() def Draw(*o): for M in o: soa = np.array(M) x,y= zip(*soa) #estrae dati da soa #print x,y plt.plot(x,y) plt.draw() def Show(): plt.show() pass def MatrixTrasl(M,T): row= len(M) col= 2 #X e Y for i in range(row): for j in range (col): M[i][j] = M[i][j]+T[j] return M def MatrixNew (NR,NC,val=0): return[[val for col in range (NC)] for row in range (NR)] def ProdMatrix (x,y): rowx=len(x) colx=len(x[0]) rowy=len(y) coly=len(y[0]) if colx != rowy: raise Exception("Impossibile") z=MatrixNew(rowx, coly) #print z for i in range (rowx): for j in range (colx): for k in range (coly): z[i][k]+=x[i][j]*y[j][k] return z #return printmatrix(z) #stampa in colonna def MatrixTranspose (M): NR = len(M) NC = len(M[0]) N=MatrixNew(NC,NR) #print N for r in range(NR): for c in range(NC): N[c][r] = M[r][c] return N def MatrixRoto(a): angolo = a * math.pi / 180.0 y=[[(math.cos(angolo)),-(math.sin(angolo))],[(math.sin(angolo)),(math.cos(angolo))]] return y L=12 initDraw(-L,L,-L,L) P=[[3,2],[5,2],[5,4],[6,4],[4,6],[2,4],[3,4],[3,2]] u=len(P) Draw(P) #for c in range(u): #B = ProdMatrix(MatrixRoto(90),MatrixTranspose(P)) B=[] for x,y in P: W= ProdMatrix(MatrixRoto(90),MatrixTranspose([[x,y]])) #break W=MatrixTranspose(W) B.append(W[0]) print B Draw(B) Show()