-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconvertions.py
55 lines (34 loc) · 1.1 KB
/
convertions.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
import binascii
import numpy as np
import math
def string2binary(words):
text_array = bin(int(binascii.hexlify(words), 16))
return text_array[2:]
def binary2string(string):
bits = int(string, 2)
text = binascii.unhexlify('%x' % bits)
return text
def binary2array(string):
return np.array(map(int, string))
def list2string(data):
return ''.join(map(str, data))
def dist(x, y, ax):
"""Calculating distance between two arrays along a given axis
"""
d = np.sqrt(np.sum((x-y)**2, axis=ax))
return d
def distance(posi, *arg):
if arg is not None and len(arg) != 0:
for i in arg:
for j in i:
x, y = j[0], j[1]
print('located at:', x, y)
print('to the real position: ', dist(posi, np.array([x, y]), 0))
print('')
def rotate(origin, point, angle):
angle = math.radians(angle)
ox, oy = origin
px, py = point
qx = ox + math.cos(angle) * (px - ox) - math.sin(angle) * (py - oy)
qy = oy + math.sin(angle) * (px - ox) + math.cos(angle) * (py - oy)
return qx, qy