HOME | DD
Published: 2017-04-30 17:20:20 +0000 UTC; Views: 253; Favourites: 3; Downloads: 1
Redirect to original
Description
Suppose for a moment that we do not know how to use complex numbers and still want to calculate the 4D fractal z -> z2+c (Julia and Mandelbrot are partial solutions in 2D). But we know that complex numbers can be written as (simplified) z = r*etheta, which describe a point in the 2D plane at magnitude/distance (r) from the origin, with an angle (theta) in regards to the x axis. If we ignore 'c' for a bit, the formula becomes z -> z2, that is z -> r*etheta * r*etheta, and using the power rules z -> r2 * e2*theta. Which means that z is scaled by r and rotate by theta (note this does not work for arbitrary complex multiplication). The complex number 'c' is simply added to that, so the Julia and Mandelbrot fractals can be decomposed to a single scale, rotation and translate. The code written in C is:uint32_t GeometricFractal( double z_x , double z_y , double c_x , double c_y , const uint32_t max_iterations )
{
uint32_t iterations = 0 ;
double magnitude = sqrt( z_x * z_x + z_y * z_y ) ;
do
{
// Get the angle
double theta = atan2( z_y , z_x ) ;
double cos_theta = cos( theta ) ;
double sin_theta = sin( theta ) ;
// Scale
z_x *= magnitude ;
z_y *= magnitude ;
// Rotate
double zn_x = z_x * cos_theta - z_y * sin_theta ;
double zn_y = z_y * cos_theta + z_x * sin_theta ;
// Translate
z_x = zn_x + c_x ;
z_y = zn_y + c_y ;
magnitude = sqrt( z_x * z_x + z_y * z_y ) ;
}
while ( ( ++iterations < max_iterations ) && ( magnitude < 2. ) ) ;
if ( iterations >= max_iterations ) return 0 ; // Did not escape in time, considered part of the fractal
return iterations ;
}
This is obviously slower and prone to lack of precision when deep zooming, compared to using complex numbers, but it works as can be seen from the above image (download for full size) which is a zoom into Elephant Valley (note the characteristic doubling of "antennas").
Enjoy.
























