# [cairo] [patch] enable projective transformations

Andrea Canciani ranma42 at gmail.com
Tue Aug 17 03:08:12 PDT 2010

```On Tue, Aug 17, 2010 at 12:04 PM, Arjen Nienhuis <a.g.nienhuis at gmail.com> wrote:
> On Tue, Aug 17, 2010 at 7:27 AM, Andrea Canciani <ranma42 at gmail.com> wrote:
>> On Tue, Aug 17, 2010 at 1:24 AM, Bill Spitzak <spitzak at gmail.com> wrote:
>>> Maarten Bosmans wrote:
>>>>
>>>> This is a first attempt to add projective transformations to Cairo. It
>>>> is far from complete, but mostly meant to get the discussion going
>>>> about how such a feature should be implemented.
>>>
>>> I believe if you want to concatenate transforms you need to keep 12 numbers
>>> (a 4x3 matrix) around. Otherwise not enough information is remembered so
>>> that two "rotate about the y axis by 10 degrees" can produce the same result
>>> as one "rotate about the y axis by 20 degrees". The 8 number cannot
>>> distinguish such a rotation from a horizontal scale by 1-sin(10 degrees).
>> A 2D projective transform is 3x3 (it is a linear transform in the
>> associated homogeneous space), so requires only 9 elements.
>> Or are you suggesting that using 3D transformations would be better?
>> Do you have any use case (where 2D projective transform would not be
>> enough and 3D would be needed)?
>
> It could work the same as current matrix transforms in cairo in 2D:
>
> translate(0, 10)
> rotate(r)
> translate(0, -10)
> draw_my_widget(foo)
>
> Could be used in 3d as:
>
> translate3d(0, 10, 0)
> rotate3d(r, 0, 0)
> translate3d(0, -10, 0)
> draw_my_widget(foo)
>
> I think you need the full 4 * 3 matrix for that.
>
To use it for 3D transformations you would need 4x3 (and 4x4 if you
want projections, too).
The question was: what would 3D transformations be used for?
(Remember: cairo uses 2D surfaces, thus the third dimension input
would be constant and its output would get discarded "soon")
```