Created
June 2, 2015 16:20
-
-
Save adusak/78d2fa22285ebe6007ed to your computer and use it in GitHub Desktop.
Functions for linear transformations
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment