Logo by Fractal Ken - Contribute your own Logo!

END OF AN ERA, FRACTALFORUMS.COM IS CONTINUED ON FRACTALFORUMS.ORG

it was a great time but no longer maintainable by c.Kleinhuis contact him for any data retrieval,
thanks and see you perhaps in 10 years again

this forum will stay online for reference
News: Visit the official fractalforums.com Youtube Channel
 
*
Welcome, Guest. Please login or register. April 23, 2024, 09:56:34 PM


Login with username, password and session length


The All New FractalForums is now in Public Beta Testing! Visit FractalForums.org and check it out!


Pages: [1]   Go Down
  Print  
Share this topic on DiggShare this topic on FacebookShare this topic on GoogleShare this topic on RedditShare this topic on StumbleUponShare this topic on Twitter
Author Topic: Problem with Mandelbrot Distance Estimator  (Read 9292 times)
0 Members and 1 Guest are viewing this topic.
Levi
Alien
***
Posts: 35


« on: December 23, 2013, 06:11:10 PM »

Hi all,

So this is my first time implementing a distance estimator and I have an issue. In the image below, my color scheme is 'mod(dist, 1.0)' where dist is the result of the distance estimator, so each ring should be 1.0 farther than the previous ring. But instead the rings actually become progressively smaller as you get farther from the center, indicating that my distance estimator is not returning a consistent estimate. Increasing the escape radius and iteration count does not fix this. Is this a bug in my implementation, or does the distance estimate normally have this problem?




GLSL code:
Code:
uniform int Iteration;
uniform float Radius;

varying vec2 Pos;

void main ()  
{
    int i;
    float x, y, x0, y0, x_temp;
    float dx, dy, dx_temp;
    float r, dr, dist;
    float escape;
    
    //Initialize iteration variables
    escape = Radius*Radius;
    x0 = Pos.x; y0 = Pos.y;
    x = 0.0; y = 0.0;
    dx = 1.0; dy = 0.0;
    
    //Run iterations
    for (i = 0; i < Iteration; i++)
    {
        //Update z'
        dx_temp = 2.0*(x*dx - y*dy) + 1.0;
        dy = 2.0*(x*dy + y*dx);
        dx = dx_temp;
        
        //Update z
        x_temp = x*x - y*y + x0;
        y = 2.0*x*y + y0;
        x = x_temp;
        
        //If escaped, quit early
        if (x*x + y*y > escape) break;
        
        //If in a periodic orbit, assume it is trapped
        if (x == 0.0 && y == 0.0) i = Iteration;
    }
    
    //Calculate distance
    r = sqrt(x*x + y*y);
    dr = sqrt(dx*dx + dy*dy);
    dist = 0.5*r*log(r)/dr;
    
    //Color
    if (i < Iteration) gl_FragColor = vec4(1.0 - mod(dist, 1.0), mod(dist, 1.0), 0.0, 1.0);
    else gl_FragColor = vec4(0.0);
}
« Last Edit: December 23, 2013, 06:20:53 PM by Levi » Logged

Math isn't the solution, math is the question.
cKleinhuis
Administrator
Fractal Senior
*******
Posts: 7044


formerly known as 'Trifox'


WWW
« Reply #1 on: December 23, 2013, 07:16:24 PM »

huh? just regarding the images, it looks perfectly fine !!!
i think you confuse what mod(distance,1) should do wink
for my eyes the behaviour is just correct, give us some more zoomed in shots to check if it behaves correctly cheesy
Logged

---

divide and conquer - iterate and rule - chaos is No random!
David Makin
Global Moderator
Fractal Senior
******
Posts: 2286



Makin' Magic Fractals
WWW
« Reply #2 on: December 23, 2013, 08:30:57 PM »

Not sure if there's a problem - what's the bailout used ? The larger the bailout value the better the results will be.

Also check this out (wait for your browser to finish on IQ's post):

http://www.fractalforums.com/3d-fractal-generation/true-3d-mandlebrot-type-fractal/msg8505/#msg8505
Logged

The meaning and purpose of life is to give life purpose and meaning.

http://www.fractalgallery.co.uk/
"Makin' Magic Music" on Jango
xenodreambuie
Conqueror
*******
Posts: 124



WWW
« Reply #3 on: December 23, 2013, 09:29:56 PM »

Yes, there is a problem. The distance estimator is wrong. For the Mandelbrot, dz should be initialized to 0. (It is only the Julia set that has dz initialized to 1; the other difference being that the Julia uses dz = z'dz, while the Mandelbrot has dz=z'dz+1).

This mistake seems to have spread over time, including the websites of some forum members; contacting them is on my to-do list  smiley
Logged

Regards, Garth
http://xenodream.com
Levi
Alien
***
Posts: 35


« Reply #4 on: December 23, 2013, 10:06:32 PM »

Thanks xenodreambule, but that didn't fix the problem.

It is hard to tell with the naked eye, but if you use a ruler (or some small object that you can check the distance with), you can verify that the rings get thinner as they get further from the center. If you look at the second picture, the outermost ring is about half the width of the innermost (excluding the one that actually contains the mandelbrot of course). 
Logged

Math isn't the solution, math is the question.
xenodreambuie
Conqueror
*******
Posts: 124



WWW
« Reply #5 on: December 23, 2013, 10:39:33 PM »

I didn't expect it to fix the 'problem' with the ring width, but it should fix problems with the accuracy of the set boundary.

I think the reason the ring width varies with distance is that it is only an estimate, and accuracy improves as iterations tend to infinity. The further out you get, the less accurate the DE is, but it's a consistent error. So you should not expect equal ring widths, but you can use various functions to change the curve.
Logged

Regards, Garth
http://xenodream.com
hobold
Fractal Bachius
*
Posts: 573


« Reply #6 on: December 23, 2013, 11:32:35 PM »

The "standard" distance estimate is not exact. It is based on analytically derived bounds (i.e. mathematically proven guarantees) for the exact distance. That means, those formulas tell you that the actual distance of a specific point is guaranteed to be between a resulting lower limit and upper limit. You get no further information which value exactly it is within that interval.

Worse yet, in applying aforementioned theory to the Mandelbrot formula, a few simplifications had to be made to keep the math tractable. Strictly speaking, the commonly used formula is merely an approximation. But the simplifying assumption that was made is that the point in question is "near" the Mandelbrot set. In other words, for all the interesting points, the mathematical guarantees still hold (with a probability bordering on certainty). Further away from the Mandelbrot set, the "standard" distance estimate formula becomes more and more inexact.
Logged
Syntopia
Fractal Molossus
**
Posts: 681



syntopiadk
WWW
« Reply #7 on: December 24, 2013, 12:28:26 AM »

Hobold is right, the distance estimate is only valid near the boundary.

There is a DE-based 2D Mandelbrot in Fragmentarium ("Mandelbrot-DE.frag") - I get similar results (see attached).

Yes, there is a problem. The distance estimator is wrong. For the Mandelbrot, dz should be initialized to 0. (It is only the Julia set that has dz initialized to 1; the other difference being that the Julia uses dz = z'dz, while the Mandelbrot has dz=z'dz+1).

Looking at the code, I think it is correct: notice, that the initial values (set in the line "dx = 1.0; dy = 0.0;") are not used at all, since x and y are both zero in the first iteration. So after the first iteration, (dx,dy)=(1,0), and (x,y)=(x0,y0), which seems to match the definitions on Wikipedia: http://en.wikipedia.org/wiki/Mandelbrot_set#Exterior_distance_estimation


* de.png (26.15 KB, 640x385 - viewed 670 times.)
Logged
xenodreambuie
Conqueror
*******
Posts: 124



WWW
« Reply #8 on: December 24, 2013, 01:29:04 AM »

Looking at the code, I think it is correct: notice, that the initial values (set in the line "dx = 1.0; dy = 0.0;") are not used at all, since x and y are both zero in the first iteration.

Oops, you are right that it doesn't matter here. But it is not correct as a matter of principle; it is just getting away with the special case of starting from the critical point (0,0) and will cause problems if starting from a different critical point, as should happen for some formulas other than z^2+c.
Logged

Regards, Garth
http://xenodream.com
Levi
Alien
***
Posts: 35


« Reply #9 on: December 24, 2013, 05:24:06 AM »

Thank you guys! So it is an issue with this method of distance approximation. That is unfortunate, since it means ray marching will be slower in implementation than theory. But at least I can rest assured that I've done it correctly!

Now on to ray marching. Wish me luck!
Logged

Math isn't the solution, math is the question.
jdebord
Explorer
****
Posts: 44


« Reply #10 on: December 27, 2013, 05:32:04 PM »

But it is not correct as a matter of principle; it is just getting away with the special case of starting from the critical point (0,0) and will cause problems if starting from a different critical point, as should happen for some formulas other than z^2+c.

How do you initialize the derivative when the critical point is not zero ?
Logged
xenodreambuie
Conqueror
*******
Posts: 124



WWW
« Reply #11 on: December 27, 2013, 08:44:38 PM »

How do you initialize the derivative when the critical point is not zero ?

It should be initialized to 0 for the Mandelbrot and 1 for Julia. Actually z' is 0 whenever starting from a critical point, so the Mandelbrot initialization shouldn't matter unless you start from a noncritical point, which is not ideal anyway.
Logged

Regards, Garth
http://xenodream.com
jdebord
Explorer
****
Posts: 44


« Reply #12 on: December 28, 2013, 08:58:49 AM »

OK. Thanks.
Logged
frostfern
Forums Newbie
*
Posts: 4


« Reply #13 on: January 29, 2014, 02:17:00 AM »

Because the method uses the slope of the potential function log(|z_n|)/2^n, which is concave down rather than a straight line, the estimated "distance" will increasingly overestimate the real distance as you move away from the boundary of the set.  It's only a valid distance measure in the asymptotic sense, i.e. when zoomed in close to the boundary.  For deeper zooms it's pretty much exact distance.
Logged
Adam Majewski
Fractal Lover
**
Posts: 221


WWW
« Reply #14 on: February 20, 2015, 04:13:13 PM »

See :

https://commons.wikimedia.org/wiki/File:Part_of_Mandelbrot_set_-_Smily_Kaleidoscope.png

Here

if (distance < (DistanceMax)) color = iBoundary ;

then you only use dem near boundary

HTH
Logged
Pages: [1]   Go Down
  Print  
 
Jump to:  

Related Topics
Subject Started by Replies Views Last post
Mandelbrot Distance Estimator Zoom Movies Showcase (Rate My Movie) cKleinhuis 4 3805 Last post March 25, 2008, 12:53:41 PM
by lycium
Distance Estimator + Binary Search == Smooth !! 3D Fractal Generation David Makin 0 980 Last post June 27, 2009, 12:59:13 AM
by David Makin
Distance Estimator for Perlin noise General Discussion willvarfar 5 4039 Last post September 22, 2013, 10:00:45 AM
by Mrz00m
Mandelbrot Set Distance Estimator Rendering Problem UltraFractal aleph0 5 11181 Last post April 30, 2014, 01:08:45 AM
by aleph0
Mandelbrot distance estimation problem Help & Support Iariak 7 754 Last post November 19, 2016, 04:14:35 PM
by Iariak

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines

Valid XHTML 1.0! Valid CSS! Dilber MC Theme by HarzeM
Page created in 0.192 seconds with 24 queries. (Pretty URLs adds 0.011s, 2q)