admin管理员组文章数量:1401401
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:
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.
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:
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.
1 Answer
Reset to default 1so 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()));
本文标签: cMandelbrot coordinates to Julia setStack Overflow
版权声明:本文标题:c++ - Mandelbrot coordinates to Julia set - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744307656a2599875.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
double
math as inmouse.x / 800.0 ...
, yetfloat
math elsewhere? – chux Commented Mar 22 at 17:18mouse
variable is justsf::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 – NeKon Commented Mar 22 at 17:35double
when rest of code usesfloat
? 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 usingdouble
orfloat
everywhere. – chux Commented Mar 22 at 18:11