How to plot isosurfaces using 3 vector columns of data?

18 views (last 30 days)
Bacha Munir on 3 Jun 2024
Commented: Bacha Munir on 25 Jun 2024
I have 4 columns. The first three are the x,y, and z coordinates while the last one is the iso level. How can I plot them in Matlab?. thanks
Mathieu NOE on 3 Jun 2024
what are we supposed to do with the iso level - to do a countour plot ?
you can first plot your x,y,z data as a scatter plot
figure
scatter3(data(:,1), data(:,2), data(:,3))

Mathieu NOE on 3 Jun 2024
Edited: Mathieu NOE on 3 Jun 2024
maybe this ?
pretty much what you could obtain with contour (in principe ,but I am not sure how to make contour work on your data)
NB that I extracted the "level" Z data using a certain tolerance (tolZ), then from the raw coordinates I made a closed smoothed curve using smoothn available from the Fex : smoothn - File Exchange - MATLAB Central (mathworks.com)
hope it helps !
x = data(:,1);
y = data(:,2);
z = data(:,3);
%
figure
scatter3(x, y, z)
hold on
% get level data (here we are dealing with one value only)
level = unique(data(:,4));
level(isnan(level)) = [];
% set a tolerance on the z coordinates
tolZ = level/30;
ind = abs(data(:,3) - level)<tolZ;
xa = data(ind,1);
ya = data(ind,2);
za = data(ind,3);
% select points and re order with theta in ascending order
centroid_x = mean(xa);
centroid_y = mean(ya);
[th,r] = cart2pol(xa-centroid_x,ya-centroid_y);
[th,ia,ic] = unique(th);
r = r(ia);
za = za(ia);
% closing the curve
r(end+1) = r(1);
th(end+1) = th(1)+2*pi;
za(end+1) = za(1);
[xa,ya] = pol2cart(th,r);
xa = xa + centroid_x;
ya = ya + centroid_y;
plot3(xa, ya, za,'*g')
% create smoothed closed curve
A = smoothn({xa, ya, za},10);
xs = A{1};
ys = A{2};
zs = A{3};
% force the smoothed curve to be closed
xs(end+1) = xs(1);
ys(end+1) = ys(1);
zs(end+1) = zs(1);
plot3(xs,ys,zs,'r','linewidth',3)
Mathieu NOE on 24 Jun 2024
hello
I don't thinl smoothn is appropriate here for scattered data representing a closed surface - I got a bad result here - this is how I changed a bit your code :
clc
clearvars
fid=fopen('surface plot 1.txt');
data = [Z{1} Z{2} Z{3}];
fclose(fid);
% Remove rows containing NaN values
data = data(all(~isnan(data), 2), :);
% try do some smoothing
xx=data(:,1);yy=data(:,2);zz=data(:,3);
Zr=smoothn({xx,yy,zz});
data = [Zr{1} Zr{2} Zr{3}];
fid=fopen('geometry.txt');
geo = [Z{1} Z{2} Z{3}];
fclose(fid);
% Remove rows containing NaN values
geo = geo(all(~isnan(geo), 2), :);
%% Run program
[t,tnorm]=MyRobustCrust(data(:,1:3));
%% plot of the output triangulation
figure(1)
grayColor = [.7 .7 .7];
title('Output Triangulation','fontsize',14)
p = trisurf(t,data(:,1),data(:,2),data(:,3));
p.EdgeColor = 'none';
p.FaceColor = 'm';
view(-40,24)
box on
camlight(40,40)
camlight(-20,-10)
% now add the geometry dots
%
hold on
scatter3(geo(:,1),geo(:,2),geo(:,3),5,'filled');
hold off
this also may interest you if you need to smooth the surface
Bacha Munir on 25 Jun 2024
Ok brother. Thank you so much.