• April 19, 2021, 08:09:37 PM

Login with username, password and session length

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

0 Members and 1 Guest are viewing this topic.

Offline iRyanBell

  • Strange Attractor
  • ******
  • Posts: 88
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

Offline gerrit

  • 3f
  • ******
  • Posts: 2402
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) + #pixel
bailout:
  |z| <= @bailout
default:
  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 = #pixel
loop:
  z = fbox(real(z)) + 1i*fbox(imag(z))
  z = @mu * fball(z) + @seed
bailout:
  |z| <= @bailout
default:
  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
}

Offline iRyanBell

  • Strange Attractor
  • ******
  • Posts: 88
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.


Offline iRyanBell

  • Strange Attractor
  • ******
  • Posts: 88
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.

Offline iRyanBell

  • Strange Attractor
  • ******
  • Posts: 88
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[1]*b[2] - a[2]*b[1],
a[2]*b[0] - a[0]*b[2],
a[0]*b[1] - a[1]*b[0],
}
}

func rot(v []float64, q []float64) []float64 {
r := []float64{}
u := []float64{q[0], q[1], q[2]}
s := q[3]
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[0]-trapPos[0]), 2) + math.Pow((v[1]-trapPos[1]), 2) + math.Pow((v[2]-trapPos[2]), 2)
And a shade calculated as:
Code: [Select]
dist := float64(i) + 1 - (math.Log(math.Log(abs(v))))/math.Log(escape)


xx
Reference Point for Reference Orbit

Started by mrmath on Fractal Mathematics And New Theories

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

Started by 3DickUlus on Programming

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

Started by Mr Rebooted on Programming

11 Replies
461 Views
Last post November 10, 2020, 02:03:44 PM
by Mr Rebooted
xx
Changing permutation reference point during calculation

Started by jjrv on Fractal Mathematics And New Theories

3 Replies
345 Views
Last post October 27, 2018, 01:49:45 PM
by claude
xx
mandelbox

Started by mclarekin on Fractal Image Gallery

0 Replies
245 Views
Last post October 10, 2018, 08:42:33 AM
by mclarekin