Skip to content

Instantly share code, notes, and snippets.

@jpablo
Created April 29, 2011 06:21
Show Gist options
  • Save jpablo/947937 to your computer and use it in GitHub Desktop.
Save jpablo/947937 to your computer and use it in GitHub Desktop.
Stereographic projection script for MathMap filter (Gimp)
filter inv_stereo2 (image in,
float zoom:1-20(10),
float warp:-5-5(1),
float altura:1-20(2),
float rotx:0-6.2839(0),
float roty:0-6.2839(0),
float rotz:0-6.2839(0)
)
# mathmap: http://www.complang.tuwien.ac.at/schani/mathmap/
xn = zoom*x ;
yn = zoom*y ;
xcor = X * warp;
den = altura^2 + xn^2 + yn^2;
# del plano estereografico a la esfera
xesf = 2*altura*xn / den;
yesf = 2*altura*yn / den;
zesf = 1-( 2*altura^2 ) / den;
# rotacion x
xrot1 = xesf;
yrot1 = yesf*cos(rotx)-zesf*sin(rotx);
zrot1 = zesf*cos(rotx)+yesf*sin(rotx);
# rotacion y
xrot2 = xrot1*cos(roty)+zrot1*sin(roty);
yrot2 = yrot1;
zrot2 = zrot1*cos(roty)-xrot1*sin(roty);
#rotacion z
xrot3 = xrot2*cos(rotz)-yrot2*sin(rotz);
yrot3 = yrot2*cos(rotz)+xrot2*sin(rotz);
zrot3 = zrot2;
# con matrices (no funciona)
mrotz = m3x3:[cos(rotz),sin(rotz),0,-sin(rotz),cos(rotz),0,0,0,1];
vrotz = mrotz*v3:[xesf,yesf,zesf];
#xrot3 = vrotz[1];
#yrot3 = vrotz[2];
#zrot3 = vrotz[3];
# de la esfera al plano original (la imagen)
xfinal = xrot3;
yfinal = yrot3;
zfinal = zrot3;
u = acos(zfinal);
v = atan(xfinal,yfinal);
#u = acos(1-2*altura^2/den);
#v = atan(altura*xn,altura*yn);
in(xy:[xcor*(u *2/pi-1), v/pi])
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment