# Hopfbrot

A 4D fractal formula related to the Mandelbulb.

History/credits:

# 1 Formula

# 1.1 Trigonometric

The Hopfbrot formula is specified using hyperspherical trigonmetry with vector power similar to the Mandelbulb. Pseudo-code:

formula(z, c):

  z = hopf(z, power) + c;

hopf(z, power):

  r = length(z);
  t = atan2(length(z.zw), length(z.xy));
  u = atan2(z.y, z.x);
  v = atan2(z.w, z.z);
  
  r = pow(r, power)
  t = t * power;
  u = u * power;
  v = v * power
  
  return
    { r * cos(t) * cos(u)
    , r * cos(t) * sin(u)
    , r * sin(t) * cos(v)
    , r * sin(t) * sin(v)
    };

Image rendering can be done via ray marching with automatic differentiation for distance estimates, for example code see github.com/lycium/FractalTracer.

# 1.2 Polynomial (Power 2)

I used Maxima computer algebra system to work out the maths for power 2 hopf(). A similar approach should work for other integer powers.

The key identities are:

cos(2 * atan2(y, x)) = (x^2 - y^2) / (x^2 + y^2)
sin(2 * atan2(y, x)) = 2 * x * y / (x^2 + y^2)

giving pseudo-code:

hopfPoly2(z):

  x2 = z.x * z.x;
  y2 = z.y * z.y;
  z2 = z.z * z.z;
  w2 = z.w * z.w;
  x2y2 = x2 + y2;
  z2w2 = z2 + w2;

  cos2u = (x2 - y2) / x2y2;
	sin2u = 2 * x * y / x2y2;
	cos2v = (z2 - w2) / z2w2;
	sin2v = 2 * z * w / z2w2;
	r2cos2t = x2y2 - z2w2;
	r2sin2t = 2 * sqrt(x2y2 * z2w2);

  return
    { r2cos2t * cos2u
    , r2cos2t * sin2u
    , r2sin2t * cos2v
    , r2sin2t * sin2v
    };

The hopfPoly2(z) is about 2x faster than the trigonometric hopf(z, 2), when tested on CPU with FractalTracer.

# 2 Animations

The whole set looks like it has some familiar cross-sections:

whole Hopfbrot

The main mini on the antenna looks like a 3D Burning Ship:

Hopfbrot mini

Both animations rendered with FractalTracer using dual numbers with the 4th derivative component set to 0, in the w=0 3D slice. Using full 4D derivatives makes the set blobby.