2

My calculations seem to be moving the image around more than scaling it. Not quite sure where I'm going wrong. I thought I followed the other post on here correctly but it's not quite right.

int xPos = ev.xbutton.x;
int yPos = ev.xbutton.y;

double xCenter = (double) ((double) ((double) xPos / X_RESN) * (rmax - rmin)) + rmin;
double yCenter = (double) ((double) ((double) yPos / Y_RESN) * (imax - imin)) + imin;

double pixelFactors[4];

if(ev.xbutton.button == 1) //Left click, zoom in
{
    rmin = (double) xCenter + (rmin + 0.3);
    rmax = (double) xCenter + (rmax - 0.3);
    imin = (double) yCenter + (imin + 0.3);
    imax = (double) yCenter + (imax - 0.3);
}
else if(ev.xbutton.button == 3) //Right click, zoom out
{
    rmin = -2;
    rmax = 2;
    imin = -2;
    imax = 2;
}
4

1 回答 1

1

You wrote:

rmin = (double) xCenter + (rmin + 0.3);
rmax = (double) xCenter + (rmax - 0.3);
imin = (double) yCenter + (imin + 0.3);
imax = (double) yCenter + (imax - 0.3);

Shouldn't there be some multiplication in there? Perhaps more like:

rmin = (double) xCenter + (rmin * 0.3);
rmax = (double) xCenter + (rmax * 0.3);
imin = (double) yCenter + (imin * 0.3);
imax = (double) yCenter + (imax * 0.3);

If you just want the mins and maxes to be closer, with xCenter and yCenter defining the middle of the image in complex-plane coordinates (ie. not pixel coordinates), I think this might be closer to what you want.

double rspan = rmax - rmin;
double ispan = imax - imin;
rmin = xCenter - (rspan * 0.3);
rmax = xCenter + (rspan * 0.3);
imin = yCenter - (rspan * 0.3);
imax = yCenter + (rspan * 0.3);

Note the casts are no longer necessary.

于 2013-04-25T05:52:52.973 回答