This is a rather primitive question coming from an electronic engineer. When applying rotate (about origin), scale (in which we shall translate towards origin and then back) and translate, does it matter in what order we do it? Why?

Basically in my case I have an image in coordinate space that goes from -2 to +2 in x and -1.5 to +1.5 in y to get ration of 4:3. This range comes from how the original mandelbrot set is plotted. I need to scale and translate this to fit into an axes (of pixels) in bitmap that goes from 0 to 800 in x axis and 0 to 600 in y axis. I am trying to understand what matrix to use to scale and translate the points from my mandelbrot set into the bitmap image.


1 Answer 1


Usually you scale first, then rotate and finally translate. The reason is because usually you want the scaling to happen along the axis of the object and rotation about the center of the object.

In your case you don't really need to worry about this generic solution though, but you only need to map range [0, 800] $\rightarrow$ [-2, 2] for x-coordinate and [0, 600] $\rightarrow$ [-1.5, 1.5] for y-coordinate, in order to map screen coordinates to real/imaginary components for Mandelbrot calculation. So this is simply done by: $$real=4*(x+0.5)/800-2$$ $$imag=3*(y+0.5)/600-1.5$$

Note that you need to calculate Mandelbrot coordinates from screen coordinates and not the other way around. This is to ensure that you evaluate the Manderbrot equation for each pixel exactly once and are not left with holes in the image or do double evaluation per pixel.

  • $\begingroup$ errrr I assign range from [-2,+2] to [0, 800] and [-1.5, 1.5] to [0, 600] and not the other way around. I thought this was clear from my question. $\endgroup$
    – quantum231
    Oct 28, 2016 at 7:50
  • 1
    $\begingroup$ @quantum231 unless you get a coordinate in the [0, 600][0, 800] space and need to know what it was in the [-1.5, 1.5][-2, 2] space to sample it. $\endgroup$ Oct 28, 2016 at 8:28
  • 2
    $\begingroup$ Yeah, but that's not correct. You need to do the inverse to evaluate the Mandelbrot equation for each pixel in your image exactly once. I should have probably emphasized that in my answer. $\endgroup$
    – JarkkoL
    Oct 28, 2016 at 8:34
  • $\begingroup$ Hi, did you derive that equation? $\endgroup$
    – quantum231
    Nov 22, 2016 at 14:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.