 • April 18, 2021, 02:10:47 AM

Login with username, password and session length

### Author Topic:  Reference implementations of 2D mandelbox?  (Read 201 times)

0 Members and 1 Guest are viewing this topic.

#### iRyanBell ##### Reference implementations of 2D mandelbox?
« on: June 20, 2020, 06:00:13 AM »
I'd like to plot a 2-dimensional version of a mandelbox. I've attempted to sketch it up a couple times with different results, but I'm not happy with either implementation -- they're close, but not quite right.

Are there any reference implementations anyone can steer me toward?

Linkback: https://fractalforums.org/index.php?topic=3603.0

#### gerrit ##### Re: Reference implementations of 2D mandelbox?
« Reply #1 on: June 20, 2020, 06:10:15 AM »
I made this UF implementation a while ago.
Code: [Select]
MBox {init:  float func fbox(float x)     float y = 0     if x < -1       y = -2-x     elseif x > 1       y = 2-x     else       y = x     endif     return y  endfunc  complex func fball(complex x)     complex y = 0     float cx = cabs(x)     if cx < .5        y = 4*x     elseif cx >= 1       y = x     else       y = x/cx^2     endif     return y  endfunc  z = 0  loop:  z = fbox(real(z)) + 1i*fbox(imag(z))  z = @mu * fball(z) + #pixelbailout:  |z| <= @bailoutdefault:  title = "MBox"  center = (0, 0)  float param bailout    caption = "Bailout value"    default = 1e16  endparam  float param mu    caption = "scale mu"    default = 2  endparam  float param bailout    caption = "bailout"    default = 1e10  endparam  switch:    type = "MBoxJulia"    seed = #pixel    bailout = bailout    mu = mu}
Code: [Select]
MBoxJulia {init:  float func fbox(float x)     float y = 0     if x < -1       y = -2-x     elseif x > 1       y = 2-x     else       y = x     endif     return y  endfunc  complex func fball(complex x)     complex y = 0     float cx = cabs(x)     if cx < .5        y = 4*x     elseif cx >= 1       y = x     else       y = x/cx^2     endif     return y  endfunc  z = #pixelloop:  z = fbox(real(z)) + 1i*fbox(imag(z))  z = @mu * fball(z) + @seedbailout:  |z| <= @bailoutdefault:  title = "MBoxJulia"  center = (0, 0)  float param bailout    caption = "Bailout value"    default = 1e16  endparam  float param mu    caption = "scale mu"    default = 2  endparam  float param bailout    caption = "bailout"    default = 1e10  endparam}

#### iRyanBell ##### Re: Reference implementations of 2D mandelbox?
« Reply #2 on: June 20, 2020, 09:47:38 AM »
Very nice!

I'm not very familiar with UltraFractal. In that loop (drawn for every pixel coordinate?), 1e16 seems like a huge value to surpass. While sweeping through the pixels, it seems like this would get stuck.

Rendering the magnitude off a few iterations, I'm beginning to see a low-res box.

#### julofi ##### Re: Reference implementations of 2D mandelbox?
« Reply #3 on: June 20, 2020, 10:20:50 AM »

#### iRyanBell ##### Re: Reference implementations of 2D mandelbox?
« Reply #4 on: June 20, 2020, 11:45:42 AM »
At a higher iteration count and a magnitude bailout, this is a little more in the ballpark. I'd like to get the sharpness a little better dialed in.

#### iRyanBell ##### Re: Reference implementations of 2D mandelbox?
« Reply #5 on: June 20, 2020, 10:29:40 PM »
Hmm, my 2D mandelbox is quickly growing in dimensionality to achieve the desired view.

Extending the folds to higher dimensions and moving the radius to a parameter:
Code: [Select]
func boxFold(v []float64) []float64 { folded := []float64{} for i := range v { if v[i] > 1 { folded = append(folded, 2-v[i]) } else if v[i] < -1 { folded = append(folded, -2-v[i]) } else { folded = append(folded, v[i]) } } return folded}
Code: [Select]
func ballFold(v []float64, r float64) []float64 { folded := []float64{} m := math.Sqrt(abs(v)) if m >= 1.0 { return v } else if m < r { for i := range v { folded = append(folded, v[i]*1/(r*r)) } return folded } s := m * m for i := range v { folded = append(folded, v[i]/s) } return folded}
Then adding basic 4d quaternion transformations with dot/cross product helpers:

Code: [Select]
func toQ(yaw float64, pitch float64, roll float64) []float64 { degreesToRad := math.Pi / 180.0 y := yaw * degreesToRad * .5 p := pitch * degreesToRad * .5 r := roll * degreesToRad * .5 qx := math.Sin(r)*math.Cos(p)*math.Cos(y) - math.Cos(r)*math.Sin(p)*math.Sin(y) qy := math.Cos(r)*math.Sin(p)*math.Cos(y) + math.Sin(r)*math.Cos(p)*math.Sin(y) qz := math.Cos(r)*math.Cos(p)*math.Sin(y) - math.Sin(r)*math.Sin(p)*math.Cos(y) qw := math.Cos(r)*math.Cos(p)*math.Cos(y) + math.Sin(r)*math.Sin(p)*math.Sin(y) return []float64{qx, qy, qz, qw}}func cross(a []float64, b []float64) []float64 { return []float64{ a*b - a*b, a*b - a*b, a*b - a*b, }}func rot(v []float64, q []float64) []float64 { r := []float64{} u := []float64{q, q, q} s := q d1 := floats.Dot(u, u) d2 := floats.Dot(u, v) c := cross(u, v) for i := range v { val := v[i] * (s*s - d1) val += 2.0 * d2 * u[i] val += 2.0 * s * c[i] r = append(r, val) } return r}
Then calculating an orbit trap coloring via:
Code: [Select]
trap := math.Pow((v-trapPos), 2) + math.Pow((v-trapPos), 2) + math.Pow((v-trapPos), 2)
And a shade calculated as:
Code: [Select]
dist := float64(i) + 1 - (math.Log(math.Log(abs(v))))/math.Log(escape)

### Similar Topics ###### Reference Point for Reference Orbit

Started by mrmath on Fractal Mathematics And New Theories

2 Replies
435 Views December 10, 2017, 05:14:03 PM
by mrmath ###### VFX Reference Platform

Started by 3DickUlus on Programming

0 Replies
147 Views June 23, 2020, 12:49:22 AM
by 3DickUlus ###### How to get second reference when using Perturbation Theory?

Started by Mr Rebooted on Programming

11 Replies
459 Views November 10, 2020, 02:03:44 PM
by Mr Rebooted ###### Changing permutation reference point during calculation

Started by jjrv on Fractal Mathematics And New Theories

3 Replies
345 Views October 27, 2018, 01:49:45 PM
by claude ###### once I was a mandelbox

Started by udo2013 on Fractal movie gallery

1 Replies
223 Views May 25, 2019, 05:57:44 AM
by Tas_mania