<div dir="ltr"><font face="courier new,monospace"><font face="arial,helvetica,sans-serif">I'm trying to understand the affine transformations in cairo and I'm currently quite confused. I don't get the same result when using matrix_multiply() as I get when doing the matrix multiplications "manually" through numpy:<br>
<br>Consider the following python code:<br><br><span style="font-family: courier new,monospace;">import cairo</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">import numpy as np</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"># routine to convert a cairo transformation to a numpy matrix</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">def c2n(c):</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> return np.matrix([[c[0],c[1],c[4]], [c[2],c[3],c[5]], [0,0,1]])</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"># Create two cairo matrices for rotation and translation</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">mr = cairo.Matrix() ; mr.rotate(np.pi/6)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">mt = cairo.Matrix() ; mt.translate(1,1)</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"># Multiply these together and print the result</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">print mt.multiply(mr) # Yields cairo.Matrix(0.866025, 0.5, -0.5, 0.866025, 0.366025, 1.36603)</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"># Multiply these together using numpy. Note order change corresponding to first applying mr and then mt</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">print c2n(mr)*c2n(mt) # Yields matrix([[ 0.8660254, 0.5 , 1.3660254],</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> # [-0.5 , 0.8660254, 0.3660254],</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> # [ 0. , 0. , 1. ]])</span><br style="font-family: courier new,monospace;"><br>Note that the x0 and the y0 values of the result is swapped in the cairo input compared to the numpy output. <br>
<br>What is even more confusing to me is that the c-source code in git seems to be ok.<br><br>I can see several possible reasons:<br></font></font><ol><li><font face="courier new,monospace"><font face="arial,helvetica,sans-serif">From looking at this problem for too long I'm making a wrong assumption.</font></font></li>
<li><font face="courier new,monospace"><font face="arial,helvetica,sans-serif">The c-code has recently been updated to fix a bug that I have in my cairo version.</font></font></li><li><font face="courier new,monospace"><font face="arial,helvetica,sans-serif">There is a bug in the python binding.</font></font></li>
</ol>Before I probe this further, does someone have any idea of what is going on?<br><br>Thanks!<br>Dov<br><br></div>