-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathTarget.py
More file actions
51 lines (43 loc) · 2.11 KB
/
Copy pathTarget.py
File metadata and controls
51 lines (43 loc) · 2.11 KB
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
import math
class Target:
xMax = 0 # will hold the value of the maximum X value
yMax = 0 # will hold the value of the maximum Y value
xMin = 1000 # will hold the value of the minumum X value
yMin = 1000 # will hold the value of the minimum Y value
xMid = 0 # will hold the X value of the center point
yMid = 0 # will hold the Y value of the center point
#image hypotenuse
hypotenuse = 0
#actual hypotenuse
ahypotenuse = math.hypot(2, 5.5)
# default initial method that initializes variables stated above
def __init__(self, corners, isLeft):
for corner in corners: # for loop that iterates through each corner array in the given array
x = corner[0][0]
y = corner[0][1]
if self.xMax < x: # series of if statements that get the minimum and maximum x and y values of the corners
self.xMax = x
if self.xMin > x:
self.xMin = x
if self.yMax < y:
self.yMax = y
if self.yMin > y:
self.yMin = y
self.hypotenuse = math.hypot(corners[0][0][0] - corners[2][0][0], corners[0][0][1] - corners[2][0][1])
self.xMid = int((self.xMax + self.xMin)/2)
self.yMid = int((self.yMax + self.yMin)/2)
self.isLeft = isLeft
# getter method for the center x and y values
def getCenter(self):
return (self.xMid, self.yMid)
# getter method for the width of the target
def getWidth(self):
return self.xMax - self.xMin
# getter method for the height of the target
def getHeight(self):
return self.yMax - self.yMin
def calculateTargetCenter(self):
delta = self.hypotenuse/self.ahypotenuse * 4
if self.isLeft:
return self.xMax + delta
return self.xMin - delta