Advertisement
Guest User

Untitled

a guest
May 9th, 2021
28
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. #objective: determine what arguments should be passed to MS-Paint-compatible transformation matrices, in order to emulate an arbitrary transform.
  2.  
  3. #in other words, given the equation:
  4. # [1 0] * [1 b] * [c 0] = [w x]
  5. # [a 1] [0 1] [0 d] [y z]
  6. #... Solve for {a,b,c,d} in terms of {w,x,y,z}
  7.  
  8. from sympy import Matrix, nonlinsolve
  9. from sympy.abc import a,b,c,d, w, x, y, z
  10. paint_operation = (
  11. Matrix([[1, 0], [a, 1]]) * #shear y
  12. Matrix([[1, b], [0, 1]]) * #shear x
  13. Matrix([[c, 0], [0, d]]) #scale x and y
  14. )
  15. m = Matrix([[w,x],[y,z]])
  16. solution_set = nonlinsolve(paint_operation - m, a,b,c,d)
  17. solutions = next(iter(solution_set))
  18. for name, expr in zip("a b c d".split(), solutions):
  19. print(f"{name} = {expr}")
  20.  
  21. #output:
  22. #a = y/w
  23. #b = -w*x/(-w*z + x*y)
  24. #c = w
  25. #d = -(-w*z + x*y)/w
  26.  
  27. #experimentation performed elsewhere suggests that this is the correct result
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement