3

I was working on a Mandelbrot set at first, then added a Julia set to the same window. The problem is I don't know the formula for my exact situation. Also, the Julia set slid to the bottom-left side. The issue is that it's not taking into account the zoom factor and the x, y offsets, and (for some reason) only accounting the bottom left square like 50 by 100 pixels. Here's my code and formula:

fractal image with the julia set missplaced:

fractal image with the julia set missplaced

zx = ((mouse.x / 800.0 - 0.5) / (1 / mandelbrot.get_zoom_scale())) * 6 - mandelbrot.get_x_offset() - 3.5;
zy = ((mouse.y / 600.0 - 0.5) / (1 / mandelbrot.get_zoom_scale())) * 6 - mandelbrot.get_y_offset() - 2.5;

The constructor of the class that handles all the fractals has these parameters:

FractalBase<Derived>::FractalBase()
    : max_iterations(300), basic_zoom_x(240.0f), basic_zoom_y(240.0f),
    zoom_x(basic_zoom_x), zoom_y(basic_zoom_y),
    x_offset(3.5f), y_offset(2.5f),
    zoom_factor(1.0f), zoom_speed(0.1f),
    pixels(new unsigned char[width * height * 4]), paletteSize(palette.size()),
    zoom_scale(1.0f), width(400), height(300)

So, the main problem is that it miscalculates the zx and zy parameters, not including the zoom_factor, and not accounting for the offsets. I tried a lot of different functions but just couldn't find the one that will actually work. I would like assistance with the formula.

5
  • Why use double math as in mouse.x / 800.0 ..., yet float math elsewhere? Commented Mar 22 at 17:18
  • The mouse variable is just sf::Vector2i, means it contains 2 integer values representing positioning of the mouse in the window in pixels, and as you can tell, it just have 2 integer numbers inside, so if you don't cast to the flooring number one of those, it will divide incorrectly Commented Mar 22 at 17:35
  • "... if you don't cast to the flooring number" is not the issue. Why use double when rest of code uses float? Mandelbrot's are sensitive to that sort of thing. I do not know it it makes a difference for you issue, just trying to understand why your code uses a mixture of FP types. I'd consider using double or float everywhere. Commented Mar 22 at 18:11
  • it may be, but the problem happens only with the julia set, cause with mandelbrot zoom and drag worked fine, it is the formula to convert to z exactly that causes an issue Commented Mar 22 at 18:58
  • i am like 100 percent sure it is the formula (zx, zy) problem, the actual Julia set formula works fine, but the conversion to zx and zy - that's the problem Commented Mar 22 at 19:05

1 Answer 1

2

so after a lot of trial and error and hours spent, here is the correct formula, so many hours spent on a simple formula, but it gave me so much dofamine when it started working

zx = -(mandelbrot.get_x_offset() - (mouse.x / mandelbrot.get_zoom_x()));

zy = -(mandelbrot.get_y_offset() - (mouse.y / mandelbrot.get_zoom_y()));
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.