Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from math import radians, cos, sin
- import numpy as np
- def combine(*transformations):
- result = transformations[0]
- for transformation in transformations[1:]:
- result = np.dot(result, transformation)
- return result
- def identity():
- return np.identity(3)
- def rotation(angle):
- a = radians(-angle)
- i = identity()
- i[0, 0] = cos(a)
- i[0, 1] = -sin(a)
- i[1, 0] = sin(a)
- i[1, 1] = cos(a)
- return i
- def scaling(sx, sy):
- i = identity()
- i[0, 0] = sx
- i[1, 1] = sy
- return i
- def translation(dx, dy):
- i = identity()
- i[0, 2] = dx
- i[1, 2] = dy
- return i
- def shear(k):
- i = identity()
- i[0, 1] = k
- return i
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement