-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtransforms.py
More file actions
23 lines (16 loc) · 743 Bytes
/
transforms.py
File metadata and controls
23 lines (16 loc) · 743 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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 # 1 when diff_y == self.perspective_point_y / 0 when diff_y = 0
factor_y = pow(factor_y, 4)
tr_x = self.perspective_point_x + diff_x * factor_y
tr_y = self.perspective_point_y - factor_y * self.perspective_point_y
return int(tr_x), int(tr_y)