[cairo] Coordinate from device to user space without a context

ed44 ed44 at xs4all.nl
Thu Nov 7 02:44:59 CET 2013


On 11/07/2013 02:03 AM, Donn wrote:
> On 06/11/2013 21:25, Bryce W. Harrington wrote:
>> But let's say your two coordinates aren't rotated or skewed, they're
>> just straight multiples with an offset.  The formula simplifies to
>> this:
>>
>> x_new = xx * x + x0; y_new = yy * y + y0;
>>
> (slimmer file attached.)
>
> I gave this one a go in my move(), where mx,my are mouse coords:
>
> public void move(double mx, double my) {
>   double xnew = mymatrix.xx * mx + mymatrix.x0;
>   double ynew = mymatrix.yy * my + mymatrix.y0;
>   stdout.printf("mx my: %G|%G maps to xnew ynew: %G|%G\n",mx,my, xnew,
> ynew);
>   x=xnew; y=ynew;
With that matrix, points are transformed from user space to device space 
( coords to pixels here).
You need the other way around.

Using the cairo matrix api you could do :
--get the matrix
--invert the matrix
--cairo_matrix_transform_point_with_that_matrix.

or , easier, use the other formulas from the previous answer.

Ed.



More information about the cairo mailing list