function [x,y,z]=nvrtrf(u,v,w,pow,A,tol) % % function [x,y,z]=nvrtrf(u,v,w,pow,A,tol) % % A one-parameter trf u,v,w => x,y,z that maps a face of % the octahedron (u+v+w=1) to an octant of the sphere is: % % bx=1-(1-u)^pow, by=1-(1-v)^pow, bz=1-(1-w)^pow, % xyz=sqrt(bx^2+by^2+bz^2), x=bx/xyz, y=by/xyz, z=bz/xyz % % An approximate two-param inverse x,y,z => u,v,w is: % % bu=1-(1-alf*x)^q x^2+y^2+z^2 = 1 % bv=1-(1-alf*y)^q where q=1/pow % bw=1-(1-alf*z)^q alf = (x+y+z)-A*(xy+yz+zx) % % uvw=bu+bv+bw and u=bu/uvw, v=bv/uvw, w=bw/uvw % % What we do: given (u,v,w) with u+v+w=1, % use Newton' method to find the (x,y,z) % s.t. x,y,z => u,v,w (the approx inverse) % % if not specified, pow is 1.55 (try 0.33) % if not specified, A is 1 (not bad for 1 given u,v,w ndx=find(s>eps&w+eps>u&u+eps>v)'; % do these, about 1/12 of the quadrant % first approximation of x,y,z - see pnodes() p=pow; q=1/p; r=1-q; uu=u(ndx); vv=v(ndx); ww=w(ndx); % need them all bta=1-B*(uu.*vv+vv.*ww+ww.*uu); % better than bta=1 bx=1-(1-bta.*uu).^p; % x-bar by=1-(1-bta.*vv).^p; % y-bar bz=1-(1-bta.*ww).^p; % z-bar alf=sqrt(bx.*bx+by.*by+bz.*bz); % the direct xx=bx./alf; yy=by./alf; zz=bz./alf; % transformation % iterate to within tol while 1 tta=xx+yy+zz; alf=tta-(tta.^2-1)*A/2; % theta=x+y+z alt=1-tta; tatpa=tta.*alt+alf; % tta*alf'(tta)+alf(tta) bu=1-(1-alf.*xx).^q; bv=1-(1-alf.*yy).^q; % u-bar, ... bw=1-(1-alf.*zz).^q; bta=bu+bv+bw; % done when bu=bta*u, ... if max(abs(ww-bw./bta))eps&w+eps>u&u>v+eps); k2=kgt(k1); % reflect x <=> y z(k2)=z(k1); y(k2)=x(k1); x(k2)=y(k1); k1=ktr(find(sw+eps&u+eps>v)); % this was hard k2=klr(sort(klr(find(s+eps>0&w>v+eps&w+eps>u)))); % really hard x(k1)=z(k2); z(k1)=y(k2); y(k1)=x(k2); % the permutation k1=find(s+eps>0&u>v+eps&u>w+eps); k2=kgt(k1); % reflect x <=> y z(k2)=z(k1); y(k2)=x(k1); x(k2)=y(k1); k1=find(s>eps); k2=ktr(k1); % at last x(k2)=x(k1); y(k2)=y(k1); z(k2)=-z(k1); % the easy one