Created
March 8, 2017 04:01
-
-
Save cjhanks/77475d73cfb24fc5f736ecd33301ffbd to your computer and use it in GitHub Desktop.
Sympy Solver Example
This file contains 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
""" | |
Example recovering the C_x and C_y equations from OpenCV's rotation matrix | |
http://docs.opencv.org/2.4/modules/imgproc/doc/geometric_transformations.html?highlight=getrotationmatrix2d#getrotationmatrix2d | |
""" | |
from sympy.solvers import solve | |
from sympy import Symbol, Eq, simplify | |
Alpha = Symbol('α') | |
Beta = Symbol('β') | |
C_x = Symbol('center.x') | |
C_y = Symbol('center.y') | |
T_x = Symbol('T_x') | |
T_y = Symbol('T_y') | |
F0 = Eq(T_x, (1 - Alpha) * C_x - Beta * C_y) | |
F1 = Eq(T_y, Beta * C_x + (1 - Alpha) * C_y) | |
system = solve([F0, F1], [C_x, C_y]) | |
# - Solve | |
F_C_x = simplify(system[C_x]) | |
F_C_y = simplify(system[C_y]) | |
print('%s = %s' % (C_x, F_C_x)) | |
print('%s = %s' % (C_y, F_C_y)) | |
""" | |
center.x = (-T_x*(α - 1) + T_y*β)/(β**2 + (α - 1)**2) | |
center.y = -(T_x*β + T_y*(α - 1))/(β**2 + (α - 1)**2) | |
""" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment