0
votes

I got a mandelbrot set I want to zoom in. The mandelbrot is calculated around a center coordinate, mandelbrot size and a zoom-level. The original mandelbrot is centered around real=-0.6 and im=0.4 with a size of 2 in both real and im.

I want to be able to click on a point in the image and calculate a new one, zoomed in around that point

The window containing it is 800x800px, so I figured this would make a click in the lower right corner be equal to a center of real=0.4 and im=-0.6, and a click in the upper left corner be real=-1.6 and im=1.4

I calculated it with:
for the real values
800a+b=0.4 => a=0.0025
0a+b=-1.6 => b=-1.6

for imaginary values
800c+d=-0.6 => c=-0.0025
0c+d=1.4 => d=1.4

However, this does not work if I continue with mandelbrot size of 2 and zoom-level of 2. Am I missing something concerning the coordinates with the zoom-levels?

1

1 Answers

2
votes

I had similar problems zooming in my C# Mandelbrot. My solution was to calculate the difference from the click position to the center in percents, multiply this with the maximum of units (width / zoom * 0.5, width = height, zoom = n * 100) from the center and add this to your current value. So My code was this (assuming I get sx and sy as parameters from the click):

        double[] o = new double[2];

        double digressLRUD = width / zoom * 0.5; //max way up or down from the center in coordinates

        double shiftCenterCursor_X = sx - width/2.0; //shift of cursor to center
        double shiftCenterCursor_X_percentage = shiftCenterCursor_X / width/2.0; //shift in percentage
        o[0] = x + digressLRUD * shiftCenterCursor_X_percentage; //new position

        double shiftCenterCursor_Y = sy - width/2.0;
        double shiftCenterCursor_Y_percentage = shiftCenterCursor_Y / width/2.0;
        o[1] = y - digressLRUD * shiftCenterCursor_Y_percentage;

This works, but you'll have to update the zoom (I use to multiply it with 2).

Another point is to move the selected center to the center of the image. I did this using some calculations:

        double maxRe = width / zoom;
        double centerRe = reC - maxRe * 0.5;

        double maxIm = height / zoom;
        double centerIm = -imC - maxIm * 0.5;

This will bring you the coordinates you have to pass your algorithm so it'll render the selected place.