Mapping a graph on a sphere.

12 ビュー (過去 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 Center および File ExchangeSurface and Mesh Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by