Mesh and Surf graphics problem

3 views (last 30 days)
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

Simon Chan
Simon Chan on 5 Mar 2022
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
Simon Chan
Simon Chan on 5 Mar 2022
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';
Dominik Jerinic
Dominik Jerinic on 5 Mar 2022
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

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!