[cairo-commit] [cairo-www] src/matrix_transform.mdwn

Carl Worth cworth at freedesktop.org
Wed Aug 22 12:34:58 PDT 2007


 src/matrix_transform.mdwn |   27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)

New commits:
commit 066f3af673ee2a42110ceba9e8af2fa42e89205c
Author: frob <frob at df.ru>
Date:   Wed Aug 22 12:34:58 2007 -0700

    basic info about matrix transformation and some transforms for everyday transformations

diff --git a/src/matrix_transform.mdwn b/src/matrix_transform.mdwn
new file mode 100644
index 0000000..951e4e4
--- /dev/null
+++ b/src/matrix_transform.mdwn
@@ -0,0 +1,27 @@
+This is some basic information about matrix transformation for people who forgot their math course or didn't have one.
+
+---
+
+Lets take that C = math.cos(A), S = math.sin(A), T = math.tan(A)
+
+mtrx have to be used in the command ctx.transform(mtrx)
+
+<table cellpadding="3" cellspacing="0" border="1" align="center">
+<tr align="center"><td>Action</td><td>Command</td><td>Matrix for transform</td></tr>
+<tr><td>Shift by dx,dy</td><td>ctx.translate(dx,dy)</td><td>mtrx = cairo.Matrix(1,0,0,1,dx,dy)</td></tr>
+<tr><td>Scale by fx,fy</td><td>ctx.scale(fx,fy)</td><td>mtrx = cairo.Matrix(fx,0,0,fy,0,0)</td></tr>
+<tr><td>Rotation to A radians<td>ctx.rotate(A)</td><td>mtrx = cairo.Matrix(C,S,-S,C,0,0)</td></tr>
+<tr><td>Rotation to A radians with center in x,y</td><td>ctx.translate(x,y); ctx.rotate(A); ctx.translate(-x,-y)</td><td>mtrx = cairo.Matrix(C,S,-S,C,x-C*x+S*y,y-S*x-C*y)</td></tr>
+<tr><td>X-skew by A</td><td>--</td><td>mtrx = cairo.Matrix(1,0,T,1,0,0)</td></tr>
+<tr><td>Y-skew by A</td><td>--</td><td>mtrx = cairo.Matrix(1,T,0,1,0,0)</td></tr>
+</table>
+
+---
+
+To apply more than one transformation you can multiply matrix. 'Unfortunately' matrix multiplication is slightly different than regular multiplication of numbers. For square matrix with N columns and N rows the rule is 'Rij == sum of Aix to Bxj products, where x = [1,N]'.
+It's easy to figure out that for matrix multiplication *A\*B is not always the same as B\*A*.
+The rule of matrix multiplication is illustrated with a picture here:
+
+<img src="http://www.gnome.ru/devel_notes/matrix_multiplication.png" width="911" height="117" border="0" alt="Matrix multiplication rule">
+
+Cairo provides matrix <a href="http://cairographics.org/manual/cairo-cairo-matrix-t.html#cairo-matrix-multiply">multiplication</a> and some other matrix <a href="http://cairographics.org/manual/cairo-cairo-matrix-t.html">functions</a>.
\ No newline at end of file


More information about the cairo-commit mailing list