Skip to content

Instantly share code, notes, and snippets.

@msg555
Created January 27, 2013 21:21
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save msg555/4650572 to your computer and use it in GitHub Desktop.
Save msg555/4650572 to your computer and use it in GitHub Desktop.
Create plots from discrete set of points. It's set to connect the first and last point together, currently.
#!/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"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment