Mapping a graph on a sphere.

9 views (last 30 days)
Vinita
Vinita on 26 Jul 2012
Hi all, 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)

Answers (1)

Conrad
Conrad on 26 Jul 2012
See the code below. It shows how to do it for two points but this is really all you need, just do the same for the other points. Note that you have so set the alpha of the mesh to 0 so that you can see the line that intersects the sphere.
% 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);
p1 = mesh(x,y,z);
px = [0.1 -0.1]; % x coordinates.
py = [0.5 -0.4]; % y coordinates.
pPhi = asin(sqrt(px.^2+py.^2)/rho);
hold on;
set(p1,'FaceAlpha',0);
p2 = plot3(px,py,rho*cos(pPhi),'ro');
set(p2,'MarkerFaceColor','red','LineStyle','-','LineWidth',2);
Conrad
  3 Comments
Albert Yam
Albert Yam on 26 Jul 2012
Conrad added the line handle for the line. Use that to remove the line.
delete(p2)
px = [0.1 -0.2]; %new x coordinates
pPhi = asin(sqrt(px.^2+py.^2)/rho);
p3 = plot3(px,py,rho*cos(pPhi),'ro');
set(p3,'MarkerFaceColor','red','LineStyle','-','LineWidth',2);
Vinita
Vinita on 27 Jul 2012
Albert that was really helpful.
But the problem is this :- There are three points (p1,p2,p3) on the sphere surface. Connect all these three by an arc on the sphere. Now I'd like to randomly select any of the two points and perform either of these operations based on a certain parameter :-
1.) Move both of them towards each other on the unit sphere itself by 5% of the present distance between them (along the smallest arc connecting them).
2.) Move only single point towards the other point by 5% of the present distance between them (along the smallest arc connecting them). .
The movement has got to be on the spherical surface itself.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!