Why does this create a stretched fractal?

Here is the pseudocode of how I set up the array representing the MandelBrot set, but it gets terribly stretched, leaving the aspect ratio 1: 1.

xStep = (maxX - minX) / width; yStep = (maxY - minY) / height; for(i = 0; i < width; i++) for(j = 0; j < height; j++) { constantReal = minReal + xStep * i; constantImag = minImag + yStep * j; image[i][j] = inSet(constantReal, constantImag); } 

Thanks!

+4
source share
3 answers

Here is the pseudo-code of how I set the array representing the MandelBrot set, but it gets terribly stretched if you leave the aspect ratio 1: 1.

 xStep = (maxX - minX) / width; yStep = (maxY - minY) / height; 

Yeah! This is because you must maintain the same aspect ratio for both the image you are drawing and the area of ​​the complex plane you want to draw. In other words, it should contain

  width maxX - minX ---------- = --------------------- height maxY - minY 

(It follows that xStep == yStep.) Your code probably does not apply this requirement.

+7
source

This is probably due to the way you display the image array. You use the width variable i as the first index, but usually the first index should be the slowest change, i.e. height.

Try changing the last line to image[j][i] = ...

0
source

Make sure your cast is correct. xStep and yStep can be integer division products instead of the expected floating point division (if this C # in your example, for some explicit garbage to work correctly).

0
source

All Articles