Mapping a graph on a sphere.

조회 수: 13 (최근 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