Path: news.mathworks.com!not-for-mail
From: "Bruno Luong" <b.luong@fogale.findmycountry>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Cubed Sphere
Date: Thu, 13 Aug 2009 22:56:03 +0000 (UTC)
Organization: FOGALE nanotech
Lines: 48
Message-ID: <h625m3$7tk$1@fred.mathworks.com>
References: <h61oju$d55$1@fred.mathworks.com> <h621hg$sfs$1@fred.mathworks.com> <h623ma$o9m$1@fred.mathworks.com>
Reply-To: "Bruno Luong" <b.luong@fogale.findmycountry>
NNTP-Posting-Host: webapp-03-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1250204163 8116 172.30.248.38 (13 Aug 2009 22:56:03 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Thu, 13 Aug 2009 22:56:03 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 390839
Xref: news.mathworks.com comp.soft-sys.matlab:563267


% Now you can chek it:

n=17;

x = 1;
y = linspace(-1,1,n);
z = y;
[X Y Z] = ndgrid(x,y,z);

S = sqrt(1./(X.^2+Y.^2+Z.^2));
X = X.*S;
Y = Y.*S;
Z = Z.*S;

C1 = [X(:) Y(:) Z(:)].';
M = makehgtform('zrotate',pi/2);
C2 = M(1:3,1:3)*C1;
M = makehgtform('zrotate',pi);
C3 = M(1:3,1:3)*C1;
M = makehgtform('zrotate',3*pi/2);
C4 = M(1:3,1:3)*C1;
M = makehgtform('yrotate',pi/2);
C5 = M(1:3,1:3)*C1;
M = makehgtform('yrotate',-pi/2);
C6 = M(1:3,1:3)*C1;

[i j] = ndgrid(1:n-1,1:n-1);
i = i(:); j=j(:);
P = [sub2ind([n n], i, j) ...
     sub2ind([n n], i+1, j) ...
     sub2ind([n n], i+1, j+1) ...
     sub2ind([n n], i, j+1)];
offset =  n^2*(0:5)';
P = bsxfun(@plus, offset, reshape(P,[1 size(P)]));
P = reshape(P, [], 4);

C = [C1 C2 C3 C4 C5 C6].';
tol = 1e-3/(n-1);
Cround = round(C/tol);
[Cround I J] = unique(Cround,'rows');
Vertices = C(I,:);
P = J(P);

figure(1); clf;
patch('Vertices',Vertices,'Faces',P,'FaceColor','g');
axis equal

% Bruno