Path: news.mathworks.com!not-for-mail
From: "Bruno Luong" <b.luong@fogale.findmycountry>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Coordinate on sphere(vector calculus)
Date: Thu, 25 Mar 2010 20:19:03 +0000 (UTC)
Organization: FOGALE nanotech
Lines: 27
Message-ID: <hoggfm$hkv$1@fred.mathworks.com>
References: <hofr3c$jlb$1@fred.mathworks.com> <hofucs$ob5$1@fred.mathworks.com> <hofvjo$lpr$1@fred.mathworks.com> <hog3fg$308$1@fred.mathworks.com> <hog428$cek$1@fred.mathworks.com> <hog4r7$otg$1@fred.mathworks.com> <hog91m$7ge$1@fred.mathworks.com> <hogb70$f9s$1@fred.mathworks.com> <hogbk2$mkc$1@fred.mathworks.com> <hogbvd$skt$1@fred.mathworks.com>
Reply-To: "Bruno Luong" <b.luong@fogale.findmycountry>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1269548343 18079 172.30.248.37 (25 Mar 2010 20:19:03 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Thu, 25 Mar 2010 20:19:03 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 390839
Xref: news.mathworks.com comp.soft-sys.matlab:620387

% Data
P0=randn(3,1)
r=rand

P1=randn(3,1);
d=r+abs(randn);
P1 = P0 + P1*(d/norm(P1))

% Engine
d = norm(P1-P0);
r2 = r^2;
a = r2/d;
b = sqrt(r2-a^2);
V = P1-P0;
Q = null(V');
theta = linspace(0,2*pi) % any angle value to parametrize P2
B = b*Q*[cos(theta); sin(theta)];
A = (a/d)*(P1-P0);
P2 = bsxfun(@plus, A+P0, B)

% Check
for idx=1:size(P2,2)
    dot(P2(:,idx)-P1,P2(:,idx)-P0) % orthogonality
    norm(P2(:,idx)-P0)-r % on the sphere
end

% Bruno