Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: Generating equidistributed points on the surface of a sphere ?? (error)
Replies: 1   Last Post: Jul 10, 2011 3:46 PM

 Messages: [ Previous | Next ]
 Animesh Pandey Posts: 63 Registered: 12/22/10
Generating equidistributed points on the surface of a sphere ?? (error)
Posted: Jul 10, 2011 2:44 PM

r = 1;

phi = linspace (0, pi, 30);
theta = linspace (0, 2*pi, 30);
[phi, theta] = meshgrid(phi, theta);

x = r.*cos(theta).*sin(phi);
y = r.*sin(theta).*sin(phi);
z = r.*cos(phi);
% This Plots the sphere !
mhndl = mesh(x, y, z);

set(mhndl, ...
'EdgeColor', [0.6,0.6,0.6], ...
'EdgeAlpha', 0.5, ...
'FaceAlpha', 0.5);

axis equal
axis off

N = 10;
a = (2*r)/N;

j = -r:a:r;
k = 0:(2*pi)/N:2*pi;

for i = 0:1:N;
x = sqrt(r*r-j(i)*j(i+1))*cos(k(i+1));
y = sqrt(r*r-j(i)*j(i+1))*sin(k(i+1));
end

hold on
plot3(x, y, j,'*');

-------------------------------------------------------------------------------------------------------------
I have to implement this algorithm to evenly plot N number of points on a sphere !

repeat N times {
Choose 'z' equidistributed from [-r:r]?-r----eeedfndr
Choose 'phi' equidistributed from [0:2*Pi]
Set x = (sqrt(r*r - z*z))* cos(phi);
Set y = (sqrt(r*r - z*z))* sin(phi);
}

I get this error :
"??? Subscript indices must either be real positive integers or logicals. "

The sphere plot is correct, this error is in the for loop !