-
Notifications
You must be signed in to change notification settings - Fork 0
/
scatter.py
64 lines (52 loc) · 1.97 KB
/
scatter.py
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
58
59
60
61
62
63
64
#!/usr/bin/env python3
from Point import Point
from Circle import Circle
import numpy as np
import matplotlib.pyplot as plt
import itertools
import math
import sys
if __name__ == '__main__':
data = np.genfromtxt(sys.argv[1], delimiter=',')
h = data[:,-3] # antepenultimate column
x = data[:,-2] # penultimate column
y = data[:,-1] # ultimate column
# throw away acceleration points
# (They're no longer saved.)
#x = _x[8:]
#y = _y[8:]
# find the period
h0 = h[0]
period = -1
for i in range(1,len(x)):
if (abs(h[i]-h0) < 0.1):
period = i
assert period!=-1, "No periodicity found!\n"
periods = math.floor(len(x) / period)
print("Period: {0}/{1}".format(period,len(x)))
i_q = int(period / 3)
c_points = [ Point(x[i],y[i]) for i in (0,i_q,i_q*2) ]
print(' '.join(map(str,c_points)))
circle = Circle.from3(*c_points)
print("(Est) 3P circle: ({0:.02f},{1:.02f}) {2:.02f}\n".format(
circle.c.x,circle.c.y,circle.r));
# calculate r and c
diameter = np.max(x)-np.min(x)
center_x = np.mean(x)
center_y = np.mean(y)
print("(Est) circle: ({0:.02f},{1:.02f}) {2:.02f}\n".format(
center_x,center_y,diameter/2));
#center_y += 26
# d_circle = plt.Circle([287.24,405.11],114.7,color='r',alpha=.2)
# d_circle = plt.Circle([circle.c.x,circle.c.y],circle.r,color='r',alpha=.2)
d_circle = plt.Circle([center_x,center_y],diameter/2,color='r',alpha=.2)
p1_point = plt.Circle([c_points[0].x,c_points[0].y],3,color='k')
p2_point = plt.Circle([c_points[1].x,c_points[1].y],3,color='k')
p3_point = plt.Circle([c_points[2].x,c_points[2].y],3,color='k')
plt.gcf().gca().add_artist(d_circle)
plt.gcf().gca().add_artist(p1_point)
plt.gcf().gca().add_artist(p2_point)
plt.gcf().gca().add_artist(p3_point)
plt.scatter(x,y)#data[:,6],data[:,7])
plt.axes().set_aspect('equal')
plt.show()