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 21:45:20 +0000 (UTC)
Organization: FOGALE nanotech
Lines: 44
Message-ID: <h621hg$sfs$1@fred.mathworks.com>
References: <h61oju$d55$1@fred.mathworks.com>
Reply-To: "Bruno Luong" <b.luong@fogale.findmycountry>
NNTP-Posting-Host: webapp-05-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1250199920 29180 172.30.248.35 (13 Aug 2009 21:45:20 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Thu, 13 Aug 2009 21:45:20 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 390839
Xref: news.mathworks.com comp.soft-sys.matlab:563246


"Matt" <matt_evans.nospam@ncsu.edu> wrote in message <h61oju$d55$1@fred.mathworks.com>...
> Hi All --
> 
> Does anyone have an algorithm to generate a cubed sphere? Ideally, I would pass the function a scalar (e.g., # of tiles per face) and would receive the Cartesian coordinates of every vertex on the cubed sphere. Thanks a bunch.
> 
> Matt

Try this:

n=10; % making (9 x 9 tiles per faces) for one of the six faces

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;

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

figure(1); clf
plot3(Vertex(:,1),Vertex(:,2),Vertex(:,3),'.');
axis equal

% Bruno