How do I create an abstract smooth 3-D shape using known points?

2 views (last 30 days)
I used the data points below and created triangular surfaces by using scatter3, and fill3. This creates the image attached but I wanted a smoother shape that isn't created by smaller peices. Is there a way to create the same shape in a non-piecewise method to produce a smooth abstract shape? This shape has symmetry so I used that to my advantage. I tried to use the surf function but it doesn't look right.
sigma1c = [18 19 22.3 24.5 25.4 28.7 31.2 33.3 34.4 35.2];
sigma2c = [.7 1.3 2.5 3.9 5 10 15 20 23 27];
sigma3c = [.7 1.3 2.5 3.9 5 10 15 20 23 27];
sigma1e = [16 18 19.5 20 21.8 24 30 35 38 45.2];
sigma2e = [16 18 19.5 20 21.8 24 30 35 38 45.2];
sigma3e = [0.1 0.3 1.2 1.2 2.7 2.6 4.9 11 14.1 30];
  2 Comments
Hayley Kieu
Hayley Kieu on 10 Apr 2024
% This code correlates to the attached image. Thanks!
sigma1c = [18 19 22.3 24.5 25.4 28.7 31.2 33.3 34.4 35.2];
sigma2c = [.7 1.3 2.5 3.9 5 10 15 20 23 27];
sigma3c = [.7 1.3 2.5 3.9 5 10 15 20 23 27];
sigma1e = [16 18 19.5 20 21.8 24 30 35 38 45.2];
sigma2e = [16 18 19.5 20 21.8 24 30 35 38 45.2];
sigma3e = [0.1 0.3 1.2 1.2 2.7 2.6 4.9 11 14.1 30];
figure(1), clf, axis image, hold on
scatter3(sigma1c,sigma2c,sigma3c,'Filled', 'MarkerEdgeColor', 'b', 'MarkerFaceColor','b')
scatter3(sigma3c,sigma1c,sigma2c,'Filled', 'MarkerEdgeColor', 'b', 'MarkerFaceColor','b')
scatter3(sigma2c,sigma3c,sigma1c,'Filled', 'MarkerEdgeColor', 'b', 'MarkerFaceColor','b')
scatter3(sigma1e,sigma2e,sigma3e,'Filled', 'MarkerEdgeColor', 'r', 'MarkerFaceColor', 'r')
scatter3(sigma3e,sigma1e,sigma2e,'Filled', 'MarkerEdgeColor', 'r', 'MarkerFaceColor', 'r')
scatter3(sigma2e,sigma3e,sigma1e,'Filled', 'MarkerEdgeColor', 'r', 'MarkerFaceColor', 'r')
sigma1 = [18 19 22.3 24.5 25.4 28.7 31.2 33.3 34.4 35.2 16 18 19.5 20 21.8 24 30 35 38 45.2];
sigma2 = [.7 1.3 2.5 3.9 5 10 15 20 23 27 .7 1.3 2.5 3.9 5 10 15 20 23 27];
sigma3 = [.7 1.3 2.5 3.9 5 10 15 20 23 27 0.1 0.3 1.2 1.2 2.7 2.6 4.9 11 14.1 30];
xlabel('\sigma_1')
ylabel('\sigma_2')
zlabel('\sigma_3')
drawpart(sigma1c, sigma2c, sigma3c, sigma1e, sigma2e, sigma3e)
drawpart(sigma1c, sigma3c, sigma2c, sigma1e, sigma3e, sigma2e)
drawpart(sigma3c, sigma1c, sigma2c, sigma3e, sigma1e, sigma2e)
drawpart(sigma3c, sigma2c, sigma1c, sigma3e, sigma2e, sigma1e)
drawpart(sigma2c, sigma3c, sigma1c, sigma2e, sigma3e, sigma1e)
drawpart(sigma2c, sigma1c, sigma3c, sigma2e, sigma1e, sigma3e)
function drawpart(sigma1c, sigma2c, sigma3c, sigma1e, sigma2e, sigma3e)
for i = 1:(length(sigma1c) - 1)
fill3([sigma1c(i:i+1), sigma1e(i)], [sigma2c(i:i+1), sigma2e(i)],[sigma3c(i:i+1), sigma3e(i)], 'm', 'FaceAlpha','0.5', 'EdgeAlpha', '0.3')
fill3([sigma1e(i:i+1), sigma1c(i+1)], [sigma2e(i:i+1), sigma2c(i+1)],[sigma3e(i:i+1), sigma3c(i+1)], 'm','FaceAlpha','0.5', 'EdgeAlpha', '0.3')
end
end

Sign in to comment.

Answers (1)

Ayush Anand
Ayush Anand on 10 Apr 2024
Hi,
"surf" requires the data passed to form a grid for a smooth plot. If the data does not naturally form a grid, one common approach is to use "meshgrid" in combination with "griddata" for interpolation of the data points. This method works by creating a grid that covers the range of your data and then interpolating the values of your data onto this grid. The interpolated grid can then be used with "surf" to create a smooth surface. You can try this as the following:
% sigma1 = ...
% sigma2 = ...
% sigma3 = ...
% Create a dense grid over your data range
[xq, yq] = meshgrid(linspace(min(sigma1), max(sigma1), 100), ...
linspace(min(sigma2), max(sigma2), 100));
% Interpolate to get z values on the grid
% Using linear interpolation here, but can also consider 'cubic' or 'v4' for smoother results
zq = griddata(sigma1, sigma2, sigma3, xq, yq, 'linear');
% Plot the surface
figure;
surf(xq, yq, zq, 'EdgeColor', 'none'); % 'none' removes gridlines for a smoother appearance
xlabel('\sigma_1');
ylabel('\sigma_2');
zlabel('\sigma_3');
You can read more about "meshgrid" and "griddata" here:
  1. https://in.mathworks.com/help/matlab/ref/meshgrid.html (Official documentation page of the "meshgrid" function)
  2. https://in.mathworks.com/help/matlab/ref/griddata.html (Official documentation page of the "griddata" function)
Hope this helps!

Products


Release

R2023b

Community Treasure Hunt

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

Start Hunting!