-
Notifications
You must be signed in to change notification settings - Fork 0
/
transforms.py
24 lines (17 loc) · 701 Bytes
/
transforms.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
def transform(self, x, y):
# return self.transform_2D(x, y)
return self.transform_perspective(x, y)
def transform_2D(self, x, y):
return int(x), int(y)
def transform_perspective(self, x, y):
lin_y = y * self.perspective_point_y / self.height
if lin_y > self.perspective_point_y:
lin_y = self.perspective_point_y
diff_x = x - self.perspective_point_x
diff_y = self.perspective_point_y - lin_y
factor_y = diff_y / self.perspective_point_y
factor_y = pow(factor_y, 4)
offset_x = diff_x * factor_y
tr_x = self.perspective_point_x + offset_x
tr_y = self.perspective_point_y - factor_y * self.perspective_point_y
return int(tr_x), int(tr_y)