[cairo] Translate and scale question
Bill Spitzak
spitzak at gmail.com
Wed Jul 22 11:32:36 PDT 2009
You are right. Correct version is:
scale(W/(xmax-xmin), H/(ymax-ymin))
translate((xmax+xmin)/2, (ymax+ymin)/2)
I keep getting this wrong. One way to remember is that when translating
two coordinate systems, you know one of them is divided by the other. To
figure out which way, pick the one that if it was larger, would make the
image bigger. That one goes on top. In this case making the window
bigger would make the image bigger.
Carl Worth wrote:
> On Wed, 2009-07-22 at 11:04 -0700, Bill Spitzak wrote:
>> W,H = size of drawing surface.
>> xmin, ymin, xmax, ymax = coordinates of lower-left and upper-right corners.
>>
>> scale((xmax-xmin)/W, (ymax-ymin)/H)
>> translate((xmax+xmin)/2, (ymax+ymin)/2)
>
> Hi Bill,
>
> I think you may have reversed some of the operations in the scaling
> there.
>
> Let's take the common case where the user wants a normalized user space,
> (0, 0) - (1.0, 1.0) so xmax-xmin = 1.0, and ymax-ymin = 1.0.
>
> In that case, your scaling code gives:
>
> cairo_scale (1.0/surface_width, 1.0/surface_height);
>
> But what is actually desired is:
>
> cairo_scale (surface_width, surface_height);
>
> I hope that helps,
>
> -Carl
>
More information about the cairo
mailing list