public
Created

Create plots from discrete set of points. It's set to connect the first and last point together, currently.

  • Download Gist
gangnam.py
Python
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
#!/usr/bin/python
#
# Example usage
# $ ./gangnam.py | gnuplot
# 9
# 0 0
# 1 1
# 2 2
# 0 2
# 1 1
# -1 1
# 0 2
# -2 2
# -1 1
 
import math
 
N = int(raw_input())
 
f = []
for i in xrange(0, N):
(x, y) = [int(x) for x in raw_input().split()]
f.append(complex(x, y))
 
F = []
for i in xrange(0, N):
ang = -2 * math.pi * i / N
rt = complex(math.cos(ang), math.sin(ang))
w = 1
r = 0
for j in xrange(0, N):
r += f[j] * w
w *= rt
F.append(r)
 
print "set parametric"
print "set samples", N + 1
 
print "plot [t=0:", N, "]",
for i in xrange(0, N):
ang = 2 * math.pi * i / N
arg = math.atan2(F[i].imag, F[i].real)
if i > 0:
print "+",
print abs(F[i]) / N, "* cos(", arg, "+", ang, "* t)",
 
print ",",
 
for i in xrange(0, N):
ang = 2 * math.pi * i / N
arg = math.atan2(F[i].imag, F[i].real)
if i > 0:
print "+",
print abs(F[i]) / N, "* sin(", arg, "+", ang, "* t)",
 
print
print "pause 555"

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.