Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #objective: determine what arguments should be passed to MS-Paint-compatible transformation matrices, in order to emulate an arbitrary transform.
- #in other words, given the equation:
- # [1 0] * [1 b] * [c 0] = [w x]
- # [a 1] [0 1] [0 d] [y z]
- #... Solve for {a,b,c,d} in terms of {w,x,y,z}
- from sympy import Matrix, nonlinsolve
- from sympy.abc import a,b,c,d, w, x, y, z
- paint_operation = (
- Matrix([[1, 0], [a, 1]]) * #shear y
- Matrix([[1, b], [0, 1]]) * #shear x
- Matrix([[c, 0], [0, d]]) #scale x and y
- )
- m = Matrix([[w,x],[y,z]])
- solution_set = nonlinsolve(paint_operation - m, a,b,c,d)
- solutions = next(iter(solution_set))
- for name, expr in zip("a b c d".split(), solutions):
- print(f"{name} = {expr}")
- #output:
- #a = y/w
- #b = -w*x/(-w*z + x*y)
- #c = w
- #d = -(-w*z + x*y)/w
- #experimentation performed elsewhere suggests that this is the correct result
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement