How to convert from plot3 to surf?
15 次查看(过去 30 天)
显示 更早的评论
Hello!
I want to convert my plot3 graph to surf graph but it says data is too much. Can anyone help me to convert it a surf graph?
Thanks for any response.
0 个评论
采纳的回答
Thiago Henrique Gomes Lobato
2021-4-18
You have scattered 3d points, surf is made for rectangular grid data. An alternative is to use a function specifically for scattered points, which in matlab is the trisurf function.
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
format short g;
format compact;
fontSize = 18;
fprintf('Beginning to run %s.m ...\n', mfilename);
counter= 0;
counter1=0;
for ky=0:1:1000
for i=0:1:89
angle=deg2rad(i);
c=ky*cos(angle);
k1ky=0.85*ky;
p1= 105*sin(angle)+105*cos(angle)-150*sin(angle)+(ky-150)*cos(angle);
p2= -105*sin(angle)+105*cos(angle)-150*sin(angle)+(ky-150)*cos(angle);
p3= 105*sin(angle)-105*cos(angle)-150*sin(angle)+(ky-150)*cos(angle);
p4= -105*sin(angle)-105*cos(angle)-150*sin(angle)+(ky-150)*cos(angle);
es1 = (0.003*p1)/c;
es2 = (0.003*p2)/c;
es3 = (0.003*p3)/c;
es4 = (0.003*p4)/c;
ss1 = max(min(es1*200000,420),-420);
ss2 = max(min(es2*200000,420),-420);
ss3 = max(min(es3*200000,420),-420);
ss4 = max(min(es4*200000,420),-420);
fs1 = ss1*100*pi*10^-3;
fs2 = ss2*100*pi*10^-3;
fs3 = ss3*100*pi*10^-3;
fs4 = ss4*100*pi*10^-3;
fs1y = fs1*0.105;
fs1x = fs1*-0.105;
fs2y = fs2*0.105;
fs2x = fs2*0.105;
fs3y = fs3*-0.105;
fs3x = fs3*-0.105;
fs4y = fs4*-0.105;
fs4x = fs4*0.105;
Tfs = fs1+fs2+fs3+fs4;
Msy = fs1x+fs2x+fs3x+fs4x;
Msx = fs1y+fs2y+fs3y+fs4y;
if k1ky <= 300
if 300*tan(angle)< k1ky
Area= (((k1ky-(300*tan(angle)))+k1ky)/2)*300;
Centroidx= (300*tan(angle)*150*(-50))/Area;
Centroidy= (((150-((k1ky-300*tan(angle))/2)) *300* (k1ky-300*tan(angle)))+ (300*tan(angle)*150* (150-((k1ky-300*tan(angle))+(300*tan(angle)/3)))))/Area;
else
Area= ((k1ky*cot(angle))*k1ky)/2;
Centroidx= (((k1ky*cot(angle))/3)-150);
Centroidy= 150-(k1ky/3);
end
else
if 300*tan(angle)<= k1ky
if k1ky-300*tan(angle) >= 300
Area = 90000;
Centroidx = 0;
Centroidy = 0;
else
Area= 90000-(((300-(k1ky-(300*tan(angle))))*((300-(k1ky-(300*tan(angle))))*cot(angle)))/2);
Centroidx = -((150-(((300-(k1ky-(300*tan(angle))))*cot(angle))/3))*(90000-Area))/Area;
Centroidy = -((((300-(k1ky-(300*tan(angle))))/3)-150)*(90000-Area))/Area;
end
else
Area= (k1ky*cot(angle))*300-((300*cot(angle))*150);
Centroidx = ((((k1ky*cot(angle))*300)*(((k1ky*cot(angle))/2)-150)) - (((300*cot(angle))*150)*((k1ky*cot(angle))-((300*cot(angle))/3)-150)))/Area;
Centroidy = -(((300*cot(angle))*150)*-50)/Area;
end
end
fc = 0.85*20*Area*10^-3;
N = max(0,fc+Tfs);
Mx = Msx + fc*Centroidy*10^-3;
My = Msy + fc*Centroidx*10^-3;
counter = counter + 1;
xAll(counter) = Mx;
yAll(counter) = My;
zAll(counter) = N;
end
end
figure
plot3(xAll,-yAll,zAll,'m.');
grid on
hold on
plot3(-yAll,xAll,zAll,'m.');
set(gca, 'CameraPosition', [607.33 607.6 2775.3]);
xlabel('Mx(kNm)')
ylabel('My(kNm)')
zlabel('N(kN)')
figure
nonNANindices = find( ~isnan(yAll) & ~isnan(xAll) & ~isnan(zAll) );
T1 = delaunay(-yAll(nonNANindices)',xAll(nonNANindices)');
T2 = delaunay(xAll(nonNANindices)',yAll(nonNANindices)');
trisurf(T1,-yAll(nonNANindices),xAll(nonNANindices),zAll(nonNANindices)),shading interp
hold on
trisurf(T2,xAll(nonNANindices),-yAll(nonNANindices),zAll(nonNANindices)),shading interp
更多回答(1 个)
Walter Roberson
2021-4-18
format short g;
format compact;
fontSize = 18;
counter= 0;
counter1=0;
for ky=0:1:1000
for i=0:1:89
angle=deg2rad(i);
c=ky*cos(angle);
k1ky=0.85*ky;
p1= 105*sin(angle)+105*cos(angle)-150*sin(angle)+(ky-150)*cos(angle);
p2= -105*sin(angle)+105*cos(angle)-150*sin(angle)+(ky-150)*cos(angle);
p3= 105*sin(angle)-105*cos(angle)-150*sin(angle)+(ky-150)*cos(angle);
p4= -105*sin(angle)-105*cos(angle)-150*sin(angle)+(ky-150)*cos(angle);
es1 = (0.003*p1)/c;
es2 = (0.003*p2)/c;
es3 = (0.003*p3)/c;
es4 = (0.003*p4)/c;
ss1 = max(min(es1*200000,420),-420);
ss2 = max(min(es2*200000,420),-420);
ss3 = max(min(es3*200000,420),-420);
ss4 = max(min(es4*200000,420),-420);
fs1 = ss1*100*pi*10^-3;
fs2 = ss2*100*pi*10^-3;
fs3 = ss3*100*pi*10^-3;
fs4 = ss4*100*pi*10^-3;
fs1y = fs1*0.105;
fs1x = fs1*-0.105;
fs2y = fs2*0.105;
fs2x = fs2*0.105;
fs3y = fs3*-0.105;
fs3x = fs3*-0.105;
fs4y = fs4*-0.105;
fs4x = fs4*0.105;
Tfs = fs1+fs2+fs3+fs4;
Msy = fs1x+fs2x+fs3x+fs4x;
Msx = fs1y+fs2y+fs3y+fs4y;
if k1ky <= 300
if 300*tan(angle)< k1ky
Area= (((k1ky-(300*tan(angle)))+k1ky)/2)*300;
Centroidx= (300*tan(angle)*150*(-50))/Area;
Centroidy= (((150-((k1ky-300*tan(angle))/2)) *300* (k1ky-300*tan(angle)))+ (300*tan(angle)*150* (150-((k1ky-300*tan(angle))+(300*tan(angle)/3)))))/Area;
else
Area= ((k1ky*cot(angle))*k1ky)/2;
Centroidx= (((k1ky*cot(angle))/3)-150);
Centroidy= 150-(k1ky/3);
end
else
if 300*tan(angle)<= k1ky
if k1ky-300*tan(angle) >= 300
Area = 90000;
Centroidx = 0;
Centroidy = 0;
else
Area= 90000-(((300-(k1ky-(300*tan(angle))))*((300-(k1ky-(300*tan(angle))))*cot(angle)))/2);
Centroidx = -((150-(((300-(k1ky-(300*tan(angle))))*cot(angle))/3))*(90000-Area))/Area;
Centroidy = -((((300-(k1ky-(300*tan(angle))))/3)-150)*(90000-Area))/Area;
end
else
Area= (k1ky*cot(angle))*300-((300*cot(angle))*150);
Centroidx = ((((k1ky*cot(angle))*300)*(((k1ky*cot(angle))/2)-150)) - (((300*cot(angle))*150)*((k1ky*cot(angle))-((300*cot(angle))/3)-150)))/Area;
Centroidy = -(((300*cot(angle))*150)*-50)/Area;
end
end
fc = 0.85*20*Area*10^-3;
N = max(0,fc+Tfs);
Mx = Msx + fc*Centroidy*10^-3;
My = Msy + fc*Centroidx*10^-3;
counter = counter + 1;
xAll(counter) = Mx;
yAll(counter) = My;
zAll(counter) = N;
end
end
figure
plot3(xAll,-yAll,zAll,'m.');
grid on
hold on
plot3(-yAll,xAll,zAll,'m.');
set(gca, 'CameraPosition', [607.33 607.6 2775.3]);
xlabel('Mx(kNm)')
ylabel('My(kNm)')
zlabel('N(kN)')
min(zAll), max(zAll)
figure
N = 50;
C1a = xAll.';
C2a = -yAll.';
C3a = zAll.';
mask = isfinite(C1a) & isfinite(C2a) & isfinite(C3a);
C1a = C1a(mask); C2a = C2a(mask); C3a = C3a(mask);
xmin = min(C1a); xmax = max(C1a);
xvec = linspace(xmin, xmax, N);
ymin = min(C2a); ymax = max(C2a);
yvec = linspace(ymin, ymax, N);
[X, Y] = meshgrid(xvec, yvec);
F = scatteredInterpolant(C1a, C2a, C3a, 'natural');
Z = F(X, Y);
surf(X, Y, Z, 'edgecolor', 'none')
xlabel('Mx(kNm)')
ylabel('My(kNm)')
zlabel('N(kN)')
hold on
min(C3a), max(C3a)
min(Z(:)), max(Z(:))
C1b = -yAll.';
C2b = xAll.';
C3b = zAll.';
mask = isfinite(C1b) & isfinite(C2b) & isfinite(C3b);
C1b = C1b(mask); C2b = C2b(mask); C3b = C3b(mask);
xmin = min(C1b); xmax = max(C1b);
xvec = linspace(xmin, xmax, N);
ymin = min(C2b); ymax = max(C2b);
yvec = linspace(ymin, ymax, N);
[X, Y] = meshgrid(xvec, yvec);
F = scatteredInterpolant(C1b, C2b, C3b, 'natural');
surf(X, Y, Z, 'edgecolor', 'none')
hold off
xlim auto; ylim auto; zlim auto
set(gca, 'CameraPosition', [607.33 607.6 2775.3]);
min(C3b), max(C3b)
min(Z(:)), max(Z(:))
figure
subplot(3,1,1); histogram(C1a)
subplot(3,1,2); histogram(C2a)
subplot(3,1,3); histogram(C3a)
Your coordinates are very biased, and when sorted into order, is not very continuous. That leads to sharp changes between values, and that leads to really big spurious peaks when you interpolate in 3D.
3 个评论
Walter Roberson
2021-4-19
10000 is the histogram count. Your coordinates are not equally distributed, they are mostly very small and very closely packed, but also not very continuous.
Walter Roberson
2021-4-19
DELTA = 0.002;
format short g;
format compact;
fontSize = 18;
counter= 0;
counter1=0;
for ky=0:1:1000
for i=0:1:89
angle=deg2rad(i);
c=ky*cos(angle);
k1ky=0.85*ky;
p1= 105*sin(angle)+105*cos(angle)-150*sin(angle)+(ky-150)*cos(angle);
p2= -105*sin(angle)+105*cos(angle)-150*sin(angle)+(ky-150)*cos(angle);
p3= 105*sin(angle)-105*cos(angle)-150*sin(angle)+(ky-150)*cos(angle);
p4= -105*sin(angle)-105*cos(angle)-150*sin(angle)+(ky-150)*cos(angle);
es1 = (0.003*p1)/c;
es2 = (0.003*p2)/c;
es3 = (0.003*p3)/c;
es4 = (0.003*p4)/c;
ss1 = max(min(es1*200000,420),-420);
ss2 = max(min(es2*200000,420),-420);
ss3 = max(min(es3*200000,420),-420);
ss4 = max(min(es4*200000,420),-420);
fs1 = ss1*100*pi*10^-3;
fs2 = ss2*100*pi*10^-3;
fs3 = ss3*100*pi*10^-3;
fs4 = ss4*100*pi*10^-3;
fs1y = fs1*0.105;
fs1x = fs1*-0.105;
fs2y = fs2*0.105;
fs2x = fs2*0.105;
fs3y = fs3*-0.105;
fs3x = fs3*-0.105;
fs4y = fs4*-0.105;
fs4x = fs4*0.105;
Tfs = fs1+fs2+fs3+fs4;
Msy = fs1x+fs2x+fs3x+fs4x;
Msx = fs1y+fs2y+fs3y+fs4y;
if k1ky <= 300
if 300*tan(angle)< k1ky
Area= (((k1ky-(300*tan(angle)))+k1ky)/2)*300;
Centroidx= (300*tan(angle)*150*(-50))/Area;
Centroidy= (((150-((k1ky-300*tan(angle))/2)) *300* (k1ky-300*tan(angle)))+ (300*tan(angle)*150* (150-((k1ky-300*tan(angle))+(300*tan(angle)/3)))))/Area;
else
Area= ((k1ky*cot(angle))*k1ky)/2;
Centroidx= (((k1ky*cot(angle))/3)-150);
Centroidy= 150-(k1ky/3);
end
else
if 300*tan(angle)<= k1ky
if k1ky-300*tan(angle) >= 300
Area = 90000;
Centroidx = 0;
Centroidy = 0;
else
Area= 90000-(((300-(k1ky-(300*tan(angle))))*((300-(k1ky-(300*tan(angle))))*cot(angle)))/2);
Centroidx = -((150-(((300-(k1ky-(300*tan(angle))))*cot(angle))/3))*(90000-Area))/Area;
Centroidy = -((((300-(k1ky-(300*tan(angle))))/3)-150)*(90000-Area))/Area;
end
else
Area= (k1ky*cot(angle))*300-((300*cot(angle))*150);
Centroidx = ((((k1ky*cot(angle))*300)*(((k1ky*cot(angle))/2)-150)) - (((300*cot(angle))*150)*((k1ky*cot(angle))-((300*cot(angle))/3)-150)))/Area;
Centroidy = -(((300*cot(angle))*150)*-50)/Area;
end
end
fc = 0.85*20*Area*10^-3;
N = max(0,fc+Tfs);
Mx = Msx + fc*Centroidy*10^-3;
My = Msy + fc*Centroidx*10^-3;
counter = counter + 1;
xAll(counter) = Mx;
yAll(counter) = My;
zAll(counter) = N;
end
end
figure
plot3(xAll,-yAll,zAll,'m.');
grid on
hold on
plot3(-yAll,xAll,zAll,'m.');
set(gca, 'CameraPosition', [607.33 607.6 2775.3]);
xlabel('Mx(kNm)')
ylabel('My(kNm)')
zlabel('N(kN)')
min(zAll), max(zAll)
figure
N = 50;
C1a = xAll.';
C2a = -yAll.';
C3a = zAll.';
mask = isfinite(C1a) & isfinite(C2a) & isfinite(C3a) & abs(C1a) <= DELTA & abs(C2a) <= DELTA;
C1a = C1a(mask); C2a = C2a(mask); C3a = C3a(mask);
xmin = min(C1a); xmax = max(C1a);
xvec = linspace(xmin, xmax, N);
ymin = min(C2a); ymax = max(C2a);
yvec = linspace(ymin, ymax, N);
[X, Y] = meshgrid(xvec, yvec);
F = scatteredInterpolant(C1a, C2a, C3a, 'natural');
Z = F(X, Y);
surf(X, Y, Z, 'edgecolor', 'none')
xlabel('Mx(kNm)')
ylabel('My(kNm)')
zlabel('N(kN)')
hold on
min(C3a), max(C3a)
min(Z(:)), max(Z(:))
C1b = -yAll.';
C2b = xAll.';
C3b = zAll.';
mask = isfinite(C1b) & isfinite(C2b) & isfinite(C3b) & abs(C1b) <= DELTA & abs(C2b) <= DELTA;
C1b = C1b(mask); C2b = C2b(mask); C3b = C3b(mask);
xmin = min(C1b); xmax = max(C1b);
xvec = linspace(xmin, xmax, N);
ymin = min(C2b); ymax = max(C2b);
yvec = linspace(ymin, ymax, N);
[X, Y] = meshgrid(xvec, yvec);
F = scatteredInterpolant(C1b, C2b, C3b, 'natural');
surf(X, Y, Z, 'edgecolor', 'none')
hold off
xlim auto; ylim auto; zlim auto
set(gca, 'CameraPosition', [607.33 607.6 2775.3]);
min(C3b), max(C3b)
min(Z(:)), max(Z(:))
figure
subplot(3,1,1); histogram(C1a)
subplot(3,1,2); histogram(C2a)
subplot(3,1,3); histogram(C3a)
figure
scatter3(C1a(:), C2a(:), C3a(:))
So what I have done here at the bottom is to restrict the output to places where the first coordinate (which is either xAll or -yall) has within +/- 0.002, and the second coordinate (which is either -yall or xall) is as well, and look at the output then. Notice from the bottom plot that even within +/- 0.0005 that you have zAll values from 0 to 2047. If you look at the histogram directly above the bottom plot, you will see that in that narrow range, some of the zAll values are "close" to 0, but others are up around 2000.
So you have rapid changes in Z values in a small area.
[C1as,idx] = sort(C1a);
C2as = C2a(idx);
C3as = C3a(idx);
plot3(C1as, C2as, C3as)
You have a number of different places pretty much at (0,0) with different Z values.
Any attempt to interpolate a smooth surface is going to have problems with changes that rapid, unless it does something like an envelope calculation (a binned maximimum intensity projection might help, for example)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Special Functions 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!