-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtransformations.py
More file actions
49 lines (39 loc) · 887 Bytes
/
Copy pathtransformations.py
File metadata and controls
49 lines (39 loc) · 887 Bytes
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
# This is where all the algorithms for the transformations are impelemented
import math
# Translation
def translate(point, tx, ty):
x, y = point
x += tx
y += ty
point = (x, y)
return point
# Scaling
def scale(point, sx, sy, fixed):
xx, yy = fixed
xx *= -1
yy *= -1
point = translate(point, xx, yy)
x, y = point
x *= sx
y *= sy
point = (x, y)
point = translate(point, xx * -1, yy * -1)
return point
# Rotation
def rotate(point, angle, fixed):
x, y = point
xx, yy = fixed
x -= xx
y -= yy
angle = math.radians(angle)
x_n = x * math.cos(angle) - y * math.sin(angle)
y_n = x * math.sin(angle) + y * math.cos(angle)
point = (x_n + xx, y_n + yy)
return point
# Shearing
def shear(point, shx, shy):
x, y = point
x += (shy * y)
y += (shx * x)
point = (x, y)
return point