Skip to content

Instantly share code, notes, and snippets.

@mu-777
Created February 1, 2020 17:10
Show Gist options
  • Save mu-777/71c173e4b09982d4f86b94cf3262bca7 to your computer and use it in GitHub Desktop.
Save mu-777/71c173e4b09982d4f86b94cf3262bca7 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import sympy as sym
# Not necessary but gives nice-looking latex output
# More info at: http://docs.sympy.org/latest/tutorial/printing.html
sym.init_printing()
x1, y1, x2, y2, x3, y3, x4, y4 = sym.symbols('x_1 y_1 x_2 y_2 x_3 y_3 x_4 y_4')
x1_, y1_, x2_, y2_, x3_, y3_, x4_, y4_ = sym.symbols("x'_1 y'_1 x'_2 y'_2 x'_3 y'_3 x'_4 y'_4")
A = sym.Matrix([[x1, y1, 1, 0, 0, 0, -x1 * x1_, -y1 * x1_],
[0, 0, 0, x1, y1, 1, -x1 * y1_, -y1 * y1_],
[x2, y2, 1, 0, 0, 0, -x2 * x2_, -y2 * x2_],
[0, 0, 0, x2, y2, 1, -x2 * y2_, -y2 * y2_],
[x3, y3, 1, 0, 0, 0, -x3 * x3_, -y3 * x3_],
[0, 0, 0, x3, y3, 1, -x3 * y3_, -y3 * y3_],
[x4, y4, 1, 0, 0, 0, -x4 * x4_, -y4 * x4_],
[0, 0, 0, x4, y4, 1, -x4 * y4_, -y4 * y4_]])
y = sym.Matrix([[x1_],[y1_],[x2_],[y2_],[x3_],[y3_],[x4_],[y4_]])
Ainv = sym.simplify(A.inv())
print(Ainv)
print(Ainv*y)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment