Re: Coordinate from device to user space without a context [RESOLVED]

"Bryce W. Harrington" <[email protected]>
Newsgroups gmane.comp.lib.cairo
Message-ID <[email protected]>
On Fri, Nov 08, 2013 at 03:21:29PM +0200, Donn wrote:
> 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.

Yeah, since convert to floating point before doing any division, then
back to int afterwards.
 
> 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);

Yep.  :-)

> 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.

Great to hear, good luck with your app!

Bryce
-- 
cairo mailing list
[email protected]
http://lists.cairographics.org/mailman/listinfo/cairo
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.