[cairo] Cairo transformations. Old bug that has been solved?

Dov Grobgeld dov.grobgeld at gmail.com
Sun Oct 9 08:21:37 PDT 2011


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:

Consider the following python code:

import cairo
import numpy as np

# routine to convert a cairo transformation to a numpy matrix
def c2n(c):
    return np.matrix([[c[0],c[1],c[4]], [c[2],c[3],c[5]], [0,0,1]])

# Create two cairo matrices for rotation and translation
mr = cairo.Matrix() ; mr.rotate(np.pi/6)
mt = cairo.Matrix() ; mt.translate(1,1)

# Multiply these together and print the result
print mt.multiply(mr)     # Yields  cairo.Matrix(0.866025, 0.5, -0.5,
0.866025, 0.366025, 1.36603)

# Multiply these together using numpy. Note order change corresponding to
first applying mr and then mt
print c2n(mr)*c2n(mt)   # Yields matrix([[ 0.8660254,  0.5      ,
1.3660254],
                        #                [-0.5      ,  0.8660254,
0.3660254],
                        #                [ 0.       ,  0.       ,  1.
]])

Note that the x0 and the y0 values of the result is swapped in the cairo
input compared to the numpy output.

What is even more confusing to me is that the c-source code in git seems to
be ok.

I can see several possible reasons:

   1. From looking at this problem for too long I'm making a wrong
   assumption.
   2. The c-code has recently been updated to fix a bug that I have in my
   cairo version.
   3. There is a bug in the python binding.

Before I probe this further, does someone have any idea of what is going on?

Thanks!
Dov
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cairographics.org/archives/cairo/attachments/20111009/e1d72a61/attachment.html>


More information about the cairo mailing list