# [cairo] Extracting The Scaling Component Of A Matrix

Lawrence D'Oliveiro ldo at geek-central.gen.nz
Sun Dec 13 14:15:36 PST 2015

```On Sat, 12 Dec 2015 12:15:17 +0100, Behdad Esfahbod wrote:

> On 15-12-11 01:51 AM, Lawrence D'Oliveiro wrote:
>
> > I construct a matrix that implements just the scaling component of
> > the CTM in the Cairo context “ctx”:
> >
> >     scaling = Matrix.scale(ctx.user_to_device_distance(Vector(1,
> > 1)))
>
> This wouldn't do what you think it does for general matrices.  Or
> maybe I don't understand what you are trying to do.  Are you only
> interested in non-skewed matrices?

import sys
from qahirah import \
Matrix, \
Vector

for \
mat \
in \
(
Matrix.scale(3),
Matrix.skew((0, 1)) * Matrix.scale(3),
Matrix.scale(3) * Matrix.skew((1, 0)),
Matrix.skew((1, 1)),
Matrix.skew((1, -1)) * Matrix.scale(3),
Matrix.scale(3) * Matrix.skew((-1, 1)),
) \
:
sys.stdout.write \
(
"scaling part of {} = {}\n"
.format
(
mat,
mat.mapdelta(Vector(1, 1))
)
)
#end for

...

scaling part of Matrix(3, 0, 0, 3, 0, 0) = Vector(3, 3)
scaling part of Matrix(3, 3, 0, 3, 0, 0) = Vector(3, 6)
scaling part of Matrix(3, 0, 3, 3, 0, 0) = Vector(6, 3)
scaling part of Matrix(1, 1, 1, 1, 0, 0) = Vector(2, 2)
scaling part of Matrix(3, -3, 3, 3, 0, 0) = Vector(6, 0)
scaling part of Matrix(3, 3, -3, 3, 0, 0) = Vector(0, 6)

Hmmm ...
```