[cairo] shear

Carl Worth cworth at cworth.org
Tue Dec 6 08:02:25 PST 2005


On Tue, 6 Dec 2005 01:12:03 -0800 (PST), Kevin Brooks wrote:
> I can't find "cairo_shear(x, y)". Can anyone show me
> how to get the shear function?

Yes, cairo has no named function for shear, but you can get a shear
effect easily enough by manually specifying the shear matrix you want
and using cairo_transform:

For example, a shear transformation that multiplies the X value of
each coordinate by 0.5 of the Y value can be achieved with:

        cairo_matrix_init (&matrix,
                           1.0, 0.0,
                           0.5, 1.0,
                           0.0, 0.0);

        cairo_transform (cr, &matrix);

Similarly, a transformation that shears Y values by 0.5 of the X
values would be:

        cairo_matrix_init (&matrix,
                           1.0, 0.5,
                           0.0, 1.0,
                           0.0, 0.0);

        cairo_transform (cr, &matrix);

It would be possible to implement something like
cairo_matrix_init_shear and cairo_matrix_shear functions, but I
haven't been  satisfied by any interface I've imagined.

First, the interface would likely need to be split into shear_x and
shear_y, but then there's an ambiguity in that naming. The first
matrix above could be named "shear_x" as it modifies the X values of
coordinates, but it could also be named "shear_y" as it results in the
Y axis being sheared from its original position.

Second, there's the question of the units for the value used in
specifying the shear transformation. One option is a proportionality
constant, (the value that appears in the matrix as I've shown
above). Another option is to specify a shear angle.

Those ambiguities, (along with the less common use case of shear as
compared to something like rotate), have prevented me from proposing
any shear function directly in cairo so far.

-Carl
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://lists.freedesktop.org/archives/cairo/attachments/20051206/a6055ec0/attachment.pgp


More information about the cairo mailing list