From a007729cd276ac828141c4637e782921f342379e Mon Sep 17 00:00:00 2001 From: Antoine Date: Tue, 19 May 2020 16:04:27 +0200 Subject: [PATCH] ajout inclusions_elliptiques.py --- inclusions_elliptiques.py | 93 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 inclusions_elliptiques.py diff --git a/inclusions_elliptiques.py b/inclusions_elliptiques.py new file mode 100644 index 0000000..8f7d671 --- /dev/null +++ b/inclusions_elliptiques.py @@ -0,0 +1,93 @@ +import numpy as np +import matplotlib.pyplot as plt + + +from random import uniform + + +def compteur(im): + nn,mm=im.shape + cpt=0 + for i in range(nn): + for j in range(mm): + if im[i,j]==1: + cpt=cpt+1 + return cpt/nn/mm + + +def ajoute(im,a,b,th,iso,nb): + nn,mm=im.shape + centers=[[0.,0.] for i in range(nb)] + theta=[0. for i in range(nb)] + + if iso==True: + for i in range(nb): + theta[i]=uniform(0,np.pi) + else: + for i in range(nb): + theta[i]=th + + for i in range(nb): + centers[i]=[uniform(0,1),uniform(0,1)] + + + + for i in range(nb): + c=max(a,b) + x=centers[i][0] + y=centers[i][1] + the=theta[i] + for j in range(int((x-c)*nn)-1,int((x+c)*nn)+1): + for k in range(int((y-c)*mm)-1,int((y+c)*mm)+1): + x1=(j+0.5)/nn + y1=(k+0.5)/mm + x2=x1*np.cos(the)+y1*np.sin(the) + y2=y1*np.cos(the)-x1*np.sin(the) + if (x2-x)**2/a**2+(y2-y)**2/b**2<=1: + if j>=nn: + l=nn + else: + l=0 + if k>=mm: + m=mm + else: + m=0 + im[j-l,k-m]=1 + + + +def image_init(N,a,b,th,iso,f): + + im=np.zeros((N,N)) + + n=int(f/np.pi/a/b) + + c=0 + while c