1
2 """Utils"""
3
4 from math import pi, sqrt, atan2
5
6 __author__ = "F. Ludwig, B. Henne"
7 __maintainer__ = "B. Henne"
8 __contact__ = "henne@dcsec.uni-hannover.de"
9 __copyright__ = "(c) 2010, DCSec, Leibniz Universitaet Hannover, Germany"
10 __license__ = "GPLv3"
11
12
14 """Euclidean distance of two nodes given by the Pythagorean formula.
15 @author: F. Ludwig"""
16 x = node1.x - node2.x
17 y = node1.y - node2.y
18 return sqrt(x**2 + y**2)
19
21 """Returns the atan2(y, x) in degrees"""
22 return (atan2(y, x) / (2*pi) * 360)
23
25 """Returns the angle in degrees between the x-axis and the line through origin and point (x,y)"""
26 if y >= 0:
27 return atan2Deg(x,y)
28 else:
29 return 360+atan2Deg(x,y)
30
32 """Returns, whether point (x1,y1) and point (x2,y2) are in a distance lower or equal distance"""
33 return round(sqrt((x2-x1)**2 + (y2-y1)**2)) <= distance
34
35 -def pointInSector(pointX, pointY, originX, originY, radius, centralAngle, direction):
36 """Returns whether a point (x,y) is in a sector of a circle with given coordinates (x,y), radius, angle and direction"""
37
38 translatX = pointX - originX
39 translatY = pointY - originY
40
41
42 if not inDistance(0, 0, translatX, translatY, radius):
43 return False
44
45
46 if centralAngle >= 360:
47 return True
48
49
50
51
52 dir = (direction+360) % 360
53
54 rightBorder = dir - (centralAngle / 2)
55
56 leftBorder = dir + (centralAngle / 2)
57
58 pointAngle = angleToXAxis(translatX, translatY)
59
60
61 leftBorder = (leftBorder - rightBorder+360) % 360
62 pointAngle = (pointAngle - rightBorder+360) % 360;
63
64
65 if pointAngle <= leftBorder:
66 return True
67 else:
68 return False
69