Created
January 27, 2013 21:21
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 "pause 555" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment