Welcome to Fractal Forums

Fractal Software => Programming => Topic started by: DarkBeam on September 29, 2013, 12:29:39 PM




Title: Project a cube into a sphere (not Riemann's way)
Post by: DarkBeam on September 29, 2013, 12:29:39 PM
I was fascinated by this image;

http://fav.me/d68vh4p

It clearly uses a 3D map; cube to sphere. Any idea to achieve this result (starting from x,y,z coords)? :D


Title: Re: Project a cube into a sphere (not Riemann's way)
Post by: knighty on September 29, 2013, 09:31:34 PM
Hey Darkbeam, nice to see you're back! :)

[warning! I haven't tested this]
One way to achieve cube to sphere transform is:

\vec{f(\vec{v})}=\vec{v}\frac{||\vec{v}||_{\infty}}{||\vec{v}||_2}

or:
Code:
Linf=max(x,y,z)
L2=sqrt(x²+y²+z²)
mult=Linf/L2
xt=x*mult
yt=y*mult
zt=z*mult

the inverse, which actually is what you need, is just:

\vec{f^{-1}(\vec{v})}=\vec{v}\frac{||\vec{v}||_2}{||\vec{v}||_{\infty}}

(trying to learn latex btw!  :embarrass:)


Title: Re: Project a cube into a sphere (not Riemann's way)
Post by: DarkBeam on September 29, 2013, 11:08:50 PM
It is very nonconformal :D but yes, I think it may be just ok - because you are a wiz :)
Anybody can render a spheric Menger with it... Please :)
I have to be sure :)


Title: Re: Project a cube into a sphere (not Riemann's way)
Post by: knighty on September 30, 2013, 10:34:11 PM
Indeed it's not conformal. Did the test. :)
Fragmentarium script:
Code:
#info Menger Distance Estimator.
#define providesInit
#include "fast-Raytracer.frag"
#include "MathUtils.frag"
#group Menger

// Number of iterations.
uniform int Iterations;  slider[0,10,20]

// Scale parameter. A perfect Menger is 3.0
uniform float Scale; slider[0.00,3,4.00]

uniform vec3 RotVector; slider[(0,0,0),(1,0,0),(1,1,1)]

// Scale parameter. A perfect Menger is 3.0
uniform float RotAngle; slider[0.00,00,360]

// Scaling center
uniform vec3 Offset; slider[(-2,-2,-2),(1,1,1),(2,2,2)]

mat3 rot;
float sc,sr;
void init() {
rot = rotationMatrix3(normalize(RotVector), RotAngle);
vec3 o=abs(Offset);
sc = max(o.x,max(o.y,o.z));
sr=sqrt(dot(o,o)+1.);
}

float DE(vec3 p)
{
#if 1
vec3 ap=abs(p);
float Linf=max(max(ap.x,ap.y),ap.z);//infinity norm
float L2=length(p);//euclidean norm
float multiplier=L2/Linf;
p*=multiplier;//Spherify transform.
float dd=multiplier*1.6;//to correct the DE. Found by try and error. there should be better formula.
#else
float dd=1.;
#endif
float r2=dot(p,p);
for(int i = 0; i<Iterations && r2<100.; i++){
p=abs(p);
if(p.y>p.x) p.xy=p.yx;
      if(p.z>p.y) p.yz=p.zy;
      if(p.y>p.x) p.xy=p.yx;
p.z=abs(p.z-1./3.*Offset.z)+1./3.*Offset.z;
p=p*Scale-Offset*(Scale-1.); dd*=Scale;
p=rot*p;
r2=dot(p,p);
}
#if 1
return (sqrt(r2)-sr)/dd;//bounding volume is a sphere
#else
p=abs(p); return (max(p.x,max(p.y,p.z))-sc)/dd;//bounding volume is a cube
#endif
}


Title: Re: Project a cube into a sphere (not Riemann's way)
Post by: DarkBeam on September 30, 2013, 10:49:20 PM
I think it's the craziest script ever, but it seems wonderful as ever, :D congrats buddy! :D


Title: Re: Project a cube into a sphere (not Riemann's way)
Post by: Nahee_Enterprises on October 01, 2013, 01:06:39 PM
    Indeed it's not conformal.   Did the test.  :)
    Fragmentarium script:
            #info Menger Distance Estimator.
              ...........
 

Nicely done !!!     :D
 


Title: Re: Project a cube into a sphere (not Riemann's way)
Post by: knighty on October 04, 2013, 10:25:38 PM
Thanks!  ;D


Title: Re: Project a cube into a sphere (not Riemann's way)
Post by: cKleinhuis on October 04, 2013, 11:21:37 PM
haha, nice one