Mesh and Surf graphics problem

Hi guys,
I have a problem to display my results in 3D graphics. When I am using MESH function for 2D graphics, results are correct according to values in table. When using SURF function for 3D graphics, I got some extra areas that shouldnt be shown because values are all zero (0) for that areas. Check lower description for details.
Methodology:
Values are shown in table "sesti_sloj" in attachement. To show 2D graphics, I am using mesh function mesh(1:360, 1:180, sesti_sloj). To show 3D graphics, I am using code as follows:
n=1;
for i=1:360
for j=1:90
[x(n), y(n), z(n)] = sph2cart(deg2rad(i),deg2rad(90-(j-1)),sesti_sloj(j,i));
n=n+1;
end
end
x_int = linspace(min(x),max(x), 200);
y_int = linspace(min(y),max(y), 200);
[X, Y] = meshgrid(x_int,y_int);
Z = griddata(x,y,z, X,Y, 'nearest');
surf(X,Y,Z)
n=1;
for i=1:360
for j=91:180
[x(n), y(n), z(n)] = sph2cart(deg2rad(i),deg2rad(90-(j-1)),sesti_sloj(j,i));
n=n+1;
end
end
x_int = linspace(min(x),max(x), 200);
y_int = linspace(min(y),max(y), 200);
[X, Y] = meshgrid(x_int,y_int);
Z = griddata(x,y,z, X,Y, 'nearest');
hold on
surf(X,Y,Z)
I f you check 2D and 3D graphics, you will see some differences that are product of some error I dont understand. For example, check "wings" in 3D graphics on the sides of smaller half-sphere part of graphics. They do not exist in 2D graphics and also those values are all zero (0) in table "sesti_sloj".
Please check if you can help.
Thank you in advance.

 Accepted Answer

You redo the meshgrid and re-sample the data via griddata may be the cause of your problem.
Just remove all additional meshgrid and griddata codes is able to generate the 3D plot easily.
load('sesti_sloj.mat');
for i=1:360
for j=1:90
[x(j,i), y(j,i), z(j,i)] = sph2cart(deg2rad(i),deg2rad(90-(j-1)),sesti_sloj(j,i));
end
end
s1=surf(x,y,z);
s1.EdgeColor = 'none';
hold on
for i=1:360
for j=91:180
[x(j-90,i), y(j-90,i), z(j-90,i)] = sph2cart(deg2rad(i),deg2rad(90-(j-1)),sesti_sloj(j,i));
end
end
s2 = surf(x,y,z);
s2.EdgeColor = 'none';

5 Comments

Thank you Simon. This helps a lot. Now, I need to remove those upper and lower "fins". According to my velues in table "sesti_sloj" i dont see there are some fast growing values range so its should be smooth as the other part of sphere. Also, with mesh function, there are no those "fins" that can be recongised. Do have an idea how to fix that?
Thank you in advance.
What is your expected output?
Better to check the methodology of dividing the data into 2 halves and use degree 1 to 90 for y-axis is correct or not.
This methodology, dividing into 2 halves, is used because I dont know how to make a full sphere with my values. X is from 1 to 360 and represents all horizontal degrees (0/360 is straight ahead, and 180 is on the back) and y is from 1 to 180 to represent vertical degrees (0 is up, 90 is horizon and 180 is down). If you know any other way to present my values in full sphere please share with me. To conclude, my final output should be a sphere.
I can think of the following but not a sphere.
So the step to convert from Spherical to Cartesian coordinates affects the result.
You may un-answer mine if someone is able to give you the correct answer.
load('sesti_sloj.mat');
sesti_sloj = [sesti_sloj;flipud(sesti_sloj)];
for i=1:360
for j=1:360
[x(j,i), y(j,i), z(j,i)] = sph2cart(deg2rad(i),deg2rad(j),sesti_sloj(j,i));
end
end
s1=surf(x,y,z);
s1.EdgeColor = 'none';
Sorry but this is wrong. y cannot be outside 1:180 so upper solutions are much closer to the right one. I have to just make this upper and lower fins smother because there shouldnt be any steep "hils" on the graphics.

Sign in to comment.

More Answers (0)

Categories

Community Treasure Hunt

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

Start Hunting!