www.gusucode.com > mbcdesign 工具箱 matlab 源码程序 > mbcdesign/@constar/private/map_to_sphere.m
function [Y,R] = map_to_sphere( X, C ) %MAP_TO_SPHERE Map points to the unit sphere % MAP_TO_SPHERE(X) returns the cartesian coordinates of the projections % of the points in X onto the sphere. % MAP_TO_SPHERE(X,C) uses C has the center of the sphere. % [Y,R] = MAP_TO_SPHERE(X) or [Y,R] = MAP_TO_SPHERE(X,C) also returns the % the radii of the points in X from the center of the sphere. % Points at the origin or the center of the sphere get mapped to north % pole. % Copyright 2000-2009 The MathWorks, Inc. and Ford Global Technologies, Inc. [n,d] = size( X ); if nargin >= 2, if any( size(C) ~= [1, d] ), error(message('mbc:constar:InvalidSize')); end X = X - repmat( C, n, 1 ); end if d < 2, Y = sign( X ); R = abs( X ); end R = sqrt( sum( X.^2, 2 ) ); % compute radii ind = find( R <= 0 ); X(ind,1:end-1) = 0; % map points at the origin to the N pole X(ind,end) = 1; R(ind) = 1; Y = X./repmat( R, 1, d ); % project onto sphere % EOF