Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
kurse:efcomputergrafik:kw45 [2019/11/05 12:01] Marcel Metzler |
kurse:efcomputergrafik:kw45 [2019/11/06 07:55] (current) Ivo Blöchliger ↷ Page name changed from kurse:efcomputergrafik:kw45m to kurse:efcomputergrafik:kw45 |
||
---|---|---|---|
Line 27: | Line 27: | ||
| | ||
+ | |||
+ | < | ||
+ | <code python Fourier_Rek.py> | ||
+ | from gpanel import * | ||
+ | import math | ||
+ | import cmath | ||
+ | import csv | ||
+ | |||
+ | # | ||
+ | # Einlesen der Daten | ||
+ | # | ||
+ | Koordinaten=[] | ||
+ | print(' | ||
+ | with open(' | ||
+ | reader=csv.DictReader(csvfile) | ||
+ | for row in reader: | ||
+ | Koordinaten.append([float(row[' | ||
+ | print(' | ||
+ | # | ||
+ | # Bild zeichnen | ||
+ | # | ||
+ | makeGPanel(0, | ||
+ | move(Koordinaten[0][0], | ||
+ | for ko in Koordinaten: | ||
+ | draw(ko[0], | ||
+ | delay(1000) | ||
+ | clear() | ||
+ | # | ||
+ | # Berechnen der Fourierkoeffizienten | ||
+ | # Teil 1: Init. | ||
+ | # | ||
+ | anzP=len(Koordinaten) | ||
+ | dt=1/ | ||
+ | kMax=int(math.floor(anzP/ | ||
+ | print(str(anzP)+' | ||
+ | print(str(2*kMax+1)+" | ||
+ | c=[] | ||
+ | for k in range(2*kMax+1): | ||
+ | c.append(complex(0, | ||
+ | f=open(' | ||
+ | # | ||
+ | # Berechnen der Fourierkoeffizienten | ||
+ | # Teil 2: c_k von -kmax <= k <= kmax | ||
+ | # | ||
+ | for k in range(-kMax, | ||
+ | for i in range(anzP): | ||
+ | kshift=k+kMax | ||
+ | c[kshift]=c[kshift]+complex(Koordinaten[i][0], | ||
+ | c[kshift]=complex(round(c[kshift].real, | ||
+ | f.write(str(c[kshift]) + ' | ||
+ | f.close() | ||
+ | print(' | ||
+ | # | ||
+ | # Rekonstruktion des Bildes | ||
+ | # | ||
+ | setColor(' | ||
+ | t=[] | ||
+ | t.append(0) | ||
+ | for i in range(anzP-1): | ||
+ | t.append(t[i]+dt) | ||
+ | # | ||
+ | # Startpunkt berechnen und Corsor | ||
+ | # dort abstellen | ||
+ | # | ||
+ | f=0 | ||
+ | for k in range(-kMax, | ||
+ | kshift=k+kMax | ||
+ | f=f+c[kshift]*cmath.exp(2*math.pi*k*t[0]*1j) | ||
+ | move(f.real, | ||
+ | f=0 | ||
+ | # | ||
+ | # Rest zeichnen | ||
+ | # | ||
+ | for i in range(anzP): | ||
+ | for k in range(-kMax, | ||
+ | kshift=k+kMax | ||
+ | f=f+c[kshift]*cmath.exp(2*math.pi*k*t[i]*1j) | ||
+ | draw(f.real, | ||
+ | delay(10) | ||
+ | f=0 | ||
+ | print(' | ||
+ | </ | ||
+ | </ |