Mapping a graph on a sphere.

9 次查看(过去 30 天)
Vinita
Vinita 2012-7-26
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)

回答(1 个)

Conrad
Conrad 2012-7-26
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 个评论
Albert Yam
Albert Yam 2012-7-26
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 2012-7-27
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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Surface and Mesh Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by