Plotting multi-radius spherical mesh

13 Ansichten (letzte 30 Tage)
Daniel
Daniel am 16 Mai 2014
Beantwortet: Daniel am 19 Mai 2014
I'm attempting to plot a mesh which represents a sphere sectioned into 12 logitudinal and 22 latitudinal segments. The difficultly is that each of the segments has a different radius to show it's importance. I have used the code below to draw the sphere but can not work out how to impose the importance onto the mesh points. The commented code if used with phi and theta of lengths 12, and 22 respectively gives me points, I however, wanted the whole segment surface.
out=double(int32(rand(22,12)*9));
% phi=linspace(0,pi,12);
% theta=linspace(0,2*pi,22);
phi=linspace(0,pi,13);
theta=linspace(0,2*pi,23);
[phi,theta]=meshgrid(phi,theta);
for i = 1:22
for j=1:12
% x=out.*sin(phi).*cos(theta);
% y=out.*sin(phi).*sin(theta);
% z=out.*cos(phi);
x=out.*sin(phi).*cos(theta);
y=out.*sin(phi).*sin(theta);
z=out.*cos(phi);
end
end
mesh(x,y,z)

Akzeptierte Antwort

Daniel
Daniel am 19 Mai 2014
For any one that is interested I have used the following code to anwser the question;
out=double(int32(rand(22,12)*9));
phi=linspace(0,pi,13);
theta=linspace(0,2*pi,23);
phi=[phi; phi];
theta=[theta; theta];
phi=reshape(phi,1,2*length(phi));
theta=reshape(theta,1,2*length(theta));
[phi,theta]=meshgrid(phi,theta);
r = zeros(size(phi,1),size(phi,2));
for i = 1:12
for j=1:22
r(j*2:j*2+1,i*2:i*2+1) = out(j,i);
end
end
x=r.*sin(phi).*cos(theta);
y=r.*sin(phi).*sin(theta);
z=r.*cos(phi);
mesh(x,y,z)
axis square
axis off
hidden off

Weitere Antworten (1)

Daniel
Daniel am 16 Mai 2014
Bearbeitet: Daniel am 16 Mai 2014
I do belive I have got much closer to the answer, see code below. So the question is how do I manipulate out a [22,12] matrix to scale the X,Y,Z values which are [46,26] matrix of the vertics.
out=double(int32(rand(22,12)*9));
phi2=linspace(0,pi,13);
theta2=linspace(0,2*pi,23);
phi3=[phi2; phi2];
theta3=[theta2; theta2];
phi4=reshape(phi3,1,2*length(phi3));
theta4=reshape(theta3,1,2*length(theta3));
[phi5,theta5]=meshgrid(phi4,theta4);
x=1*sin(phi5).*cos(theta5);
y=1*sin(phi5).*sin(theta5);
z=1*cos(phi5);
mesh(x,y,z)out=double(int32(rand(22,12)*9));

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by