2
votes

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;
}
1
What post were you following?Xymostech
If you don't want it to move, then why are xPos and yPos involved?luser droog
I want to center it on the area clicked and then zoom in. It's sort of doing that now but not perfectly centering for some reason.Jarrod Cabalzar

1 Answers

1
votes

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.