How to pick n random points on a sphere

Hi all, Does anybody know how to pick N random points (in my case N=4) on a unit sphere. Then draw a line connecting these points on the unit sphere.This is what i have done till now :-
theta=linspace(0,2*pi,40);
phi=linspace(0,pi,40);
[theta,phi]=meshgrid(theta,phi);
rho=1;
x=rho*sin(phi).*cos(theta);
y=rho*sin(phi).*sin(theta);
z=rho*cos(phi);
mesh(x,y,z)
axis equal
grid on
ALPHA('clear'); % renders the sphere transparent
Please help
[EDITED, Jan, copied from comments - please add informations, which are required to understand the problem, in the question, not as comments or answers. Thanks!]
Suppose that I have created a unit sphere. Now I pick 4 random points on this unit sphere. Then I need to draw a line passing through these 4 points (thus forming a quadrilateral). Later if this is successful I would like to draw a plane passing through the center of the sphere. Finally it would like to know how many lines did the plane cut through on this sphere. Hope you understand now. Please help

5 Comments

How can a line connect 4 points on a sphere? Do you want a line from point to point in the surface of the sphere? A straight line or a spline?
Jan
Jan on 25 Jul 2012
Edited: Jan on 25 Jul 2012
After your refinement:Now it is a little bit clearer. "A line" means, that you want to connect the 4 points with 4 lines, correct? What happens, if the 4 points are identical or lye on a great circle?
Your question is very general. What kind of help do you expect?
Jan that issue is solved now. I have another complicated problem now. I have this graph :- http://static.inky.ws/image/2485/image.jpg I want to map these points on a unit sphere now(All the 4 points should lie on surface of the sphere, the lines connecting them shouldnt lie on the sphere but should be euclidean distances and thus cutting through the sphere). Do you know how to do it.
% Generate a unit sphere
theta=linspace(0,2*pi,20);
phi=linspace(0,pi,20);
[theta,phi]=meshgrid(theta,phi);
rho=1;
x=rho*sin(phi).*cos(theta);
y=rho*sin(phi).*sin(theta);
z=rho*cos(phi);
mesh(x,y,z)
Comment posted as answer by Kelly Mariotto:
Hello,
Can please anyone give me the solution for the angles of 7 points on the sphere?
Thank you very much.
Kelly
What is the question about 7 points in the sphere? Angles between what and what? Angles measured from what point of view? https://stackoverflow.com/questions/55734075/calculate-angle-between-3d-points-of-sphere-with-specific-center

Sign in to comment.

Answers (1)

I also do not understand what you mean by connecting 4 points on a sphere, but to answer the first part of your question,
this is how you would generate random points on a sphere:
TH = 2*pi*rand(1,1e4);
PH = asin(-1+2*rand(1,1e4));
[X,Y,Z] = sph2cart(TH,PH,1);
plot3(X,Y,Z,'.','markersize',1)
axis equal vis3d

Tags

Asked:

on 25 Jul 2012

Commented:

on 6 Oct 2020

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!