Mapping a graph on a sphere.
9 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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)
0 Commenti
Risposte (1)
Conrad
il 26 Lug 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 Commenti
Albert Yam
il 26 Lug 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);
Vedere anche
Categorie
Scopri di più su Surface and Mesh Plots in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!