The Math Forum

Search All of the Math Forum:

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

Math Forum » Discussions » Software » comp.soft-sys.matlab

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

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   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
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

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));

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 !

Please Help !

Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© The Math Forum at NCTM 1994-2018. All Rights Reserved.