Second assignment
This commit is contained in:
parent
2d805fe922
commit
52a83beb3b
|
@ -0,0 +1,65 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# vim:fenc=utf-8
|
||||
#
|
||||
# Copyright © 2018 pavle <pavle.portic@tilda.center>
|
||||
#
|
||||
# Distributed under terms of the MIT license.
|
||||
|
||||
import numpy as np
|
||||
import os
|
||||
|
||||
def main():
|
||||
os.chdir(raw_input())
|
||||
files = get_files()
|
||||
files.sort()
|
||||
|
||||
for file in files:
|
||||
with open(file) as f:
|
||||
i = 0
|
||||
for line in f:
|
||||
coords = calculate_coordinates(line)
|
||||
print file, i, coords[0], coords[1]
|
||||
i += 1
|
||||
f.close()
|
||||
|
||||
|
||||
def get_files():
|
||||
out = []
|
||||
for root, dirs, files in os.walk('.'):
|
||||
for file in files:
|
||||
out.append(os.path.join(root[2:], file))
|
||||
|
||||
return out
|
||||
|
||||
|
||||
def calculate_coordinates(numbers):
|
||||
numbers = numbers.split()
|
||||
numbers = [ float(x) for x in numbers ]
|
||||
O = (numbers[0], numbers[1])
|
||||
X = tuple(np.subtract((numbers[2], numbers[3]), O))
|
||||
Y = tuple(np.subtract((numbers[4], numbers[5]), O))
|
||||
A = tuple(np.subtract((numbers[6], numbers[7]), O))
|
||||
|
||||
phi = -get_angle(X)
|
||||
|
||||
sin = np.sin(phi)
|
||||
cos = np.cos(phi)
|
||||
Y = rotate_pt(Y, sin, cos)
|
||||
A = rotate_pt(A, sin, cos)
|
||||
|
||||
if round(np.degrees(get_angle(Y))) == -90.0:
|
||||
A = (A[0], -A[1])
|
||||
|
||||
return (round(A[0], 4), round(A[1], 4))
|
||||
|
||||
|
||||
def get_angle(points):
|
||||
return np.arctan2(points[1], points[0])
|
||||
|
||||
|
||||
def rotate_pt(pt, sin, cos):
|
||||
return (pt[0]*cos - pt[1]*sin, pt[1]*cos + pt[0]*sin)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
|
@ -0,0 +1 @@
|
|||
@@DATASET_DIR@@
|
|
@ -0,0 +1,34 @@
|
|||
13\22.txt 0 35.7815 -18.1296
|
||||
13\22.txt 1 -9.44626 -53.6262
|
||||
13\22.txt 2 16.9916 -12.9725
|
||||
13\22.txt 3 -10.3751 27.3744
|
||||
13\22.txt 4 -9.73943 39.9768
|
||||
16\6.txt 0 -59.1713 5.26797
|
||||
16\6.txt 1 -6.27443 22.464
|
||||
16\6.txt 2 -11.5828 54.2479
|
||||
16\6.txt 3 -9.17361 4.10424
|
||||
16\6.txt 4 -44.7695 6.75959
|
||||
33\22.txt 0 35.5838 20.8277
|
||||
33\22.txt 1 -25.1396 -29.8328
|
||||
33\22.txt 2 -57.1496 -4.34952
|
||||
58\15.txt 0 16.0966 10.8581
|
||||
58\15.txt 1 13.1564 4.46203
|
||||
61\31.txt 0 33.0013 12.6456
|
||||
61\31.txt 1 -6.822 -18.4786
|
||||
61\31.txt 2 -15.9475 3.26773
|
||||
61\31.txt 3 -15.4166 7.76709
|
||||
61\31.txt 4 5.22033 -4.66348
|
||||
73\18.txt 0 -22.4715 16.8236
|
||||
73\18.txt 1 4.16129 8.22701
|
||||
73\18.txt 2 -10.8755 3.11816
|
||||
75\0.txt 0 -8.96761 27.1953
|
||||
75\0.txt 1 21.1004 -29.3219
|
||||
75\0.txt 2 -57.1521 -3.82554
|
||||
77\27.txt 0 -8.42885 34.8418
|
||||
77\27.txt 1 -29.5393 -25.6405
|
||||
77\27.txt 2 -1.30118 26.0443
|
||||
81\11.txt 0 -6.79602 4.22069
|
||||
81\11.txt 1 -1.28781 6.27228
|
||||
87\0.txt 0 14.0366 7.27826
|
||||
87\0.txt 1 18.8053 20.9609
|
||||
87\0.txt 2 -5.21009 -23.1269
|
|
@ -0,0 +1,5 @@
|
|||
60 67 146 119 -40.4988 233.209 100 70
|
||||
57 99 111 174 -35.4175 165.541 95 60
|
||||
90 53 186 139 218.888 -90.8745 94 74
|
||||
88 65 142 164 -24.7697 126.511 59 69
|
||||
81 97 180 179 209.55 -58.2001 99 60
|
|
@ -0,0 +1,5 @@
|
|||
88 99 172 195 215.562 -12.6165 53 51
|
||||
92 87 167 158 -11.2763 196.095 72 99
|
||||
100 69 185 151 -18.1059 191.427 54 100
|
||||
69 89 120 178 171.577 30.22 68 79
|
||||
94 99 178 157 196.078 -48.8377 61 68
|
|
@ -0,0 +1,3 @@
|
|||
89 57 180 150 -41.1153 184.317 99 97
|
||||
56 91 136 162 -50.9626 211.521 57 52
|
||||
94 99 174 173 -14.9771 216.813 55 57
|
|
@ -0,0 +1,2 @@
|
|||
54 69 152 164 -82.4881 209.798 58 88
|
||||
60 74 152 154 -61.918 214.206 67 86
|
|
@ -0,0 +1,5 @@
|
|||
59 55 140 133 -53.45 171.775 74 87
|
||||
72 96 147 169 -32.6614 203.529 80 78
|
||||
74 98 137 185 -33.4151 175.783 62 87
|
||||
56 68 112 143 149.6 -1.88816 53 51
|
||||
51 92 126 159 -49.5684 204.577 58 92
|
|
@ -0,0 +1,3 @@
|
|||
58 88 112 172 157.86 23.8044 60 60
|
||||
59 72 148 145 -56.1086 212.338 57 81
|
||||
64 69 115 161 -41.1903 127.312 56 61
|
|
@ -0,0 +1,3 @@
|
|||
85 51 155 126 -17.5914 146.752 59 63
|
||||
65 56 161 138 191.254 -91.8092 62 92
|
||||
96 93 174 180 212.846 -11.7585 55 53
|
|
@ -0,0 +1,3 @@
|
|||
73 89 166 178 201.725 -45.5099 91 58
|
||||
59 92 125 181 -51.8016 174.168 62 53
|
||||
85 73 141 152 -11.8349 141.642 63 87
|
|
@ -0,0 +1,2 @@
|
|||
77 82 136 177 188.83 12.5475 77 74
|
||||
88 89 157 172 195.935 -0.729233 92 84
|
|
@ -0,0 +1,3 @@
|
|||
83 72 150 141 179.177 -21.3892 98 77
|
||||
72 89 142 152 166.175 -15.6393 100 86
|
||||
95 54 157 127 190.776 -27.3438 74 65
|
Reference in New Issue