[cairo] Coordinate from device to user space without a context [RESOLVED]
Donn
donn.ingle at gmail.com
Fri Nov 8 14:21:29 CET 2013
On 06/11/2013 21:25, Bryce W. Harrington wrote:
> Essentially, you have two sets of coordinates, one of which is offset
> from the other, and perhaps multiplied by some factor, and maybe rotated
> or skewed. To calculate the x,y coordinates in one system from the
> other, you use this formula:
>
> x_new = xx * x + xy * y + x0;
> y_new = yx * x + yy * y + y0;
Bryce,
I've been at it for hours and some things are getting clearer.
My program does involve a tree - children with children and there will
be many nodes under rotation and skew etc. So, I needed your first
formula above.
I tried, with high-school algebra that's 24 years old and got:
userx = ( mousex - mymatrix.xy * y - mymatrix.x0 )/mymatrix.xx
usery = ( mousey - mymatrix.yx * x - mymatrix.y0 )/mymatrix.yy
(Monkey see, monkey solve. Understanding is a million miles away.)
So, that worked ;) It's "jerky" though - perhaps something to do with
doubles and rounding or such voodoo.
The "cairo function" route is way smoother:
var tm = mymatrix;
tm.invert();
//outputs user space into my,my
tm.transform_point(ref mousex, ref mousey);
I have also come to some détente with transforms and save/restore and
when in that process to calculate device->user coordinates. The mad
jumping is under control now. I hope it stays that way.
(The secret is to save mymatrix *before* doing any transforms.)
So, my thanks to Bryce and ed and this list. I couldn't have done it
without ya.
\d
More information about the cairo
mailing list