• pedrofreire's avatar
    Make shear operation area preserving (#1529) · c226bb95
    pedrofreire authored
    * Improve readability of affine transformation code
    
    * Make shear transformation area preserving
    
    The previous shear implementation did not preserve area, and we
    implement a version that does.
    
    The formula used was verified with the following sympy code:
    
    from sympy import Matrix, cos, sin, tan, simplify
    from sympy.abc import x, y, phi
    
    Xs = Matrix(
            [[1, -tan(x)],
             [0, 1]]
            )
    
    Ys = Matrix(
            [[1, 0],
             [-tan(y), 1]]
            )
    
    R = Matrix(
            [[cos(phi), -sin(phi)],
             [sin(phi), cos(phi)]]
            )
    
    RSS = Matrix(
            [[cos(phi - y)/cos(y), -cos(phi - y)*tan(x)/cos(y) - sin(phi)],
             [sin(phi - y)/cos(y), -sin(phi - y)*tan(x)/cos(y) + cos(phi)]])
    
    print(simplify(R * Ys * Xs - RSS))
    
    One thing that is not clear (and could be tested) is whether avoiding
    the explicit products and calculations in _get_inverse_affine_matrix
    really gives performance benefits - compared to doing the explicit
    calculation done in _test_transformation.
    
    * Use np.matmul instead of @
    
    The @ syntax is not supported in Python 2.
    c226bb95
functional.py 31.9 KB