3D Plot to SURF

조회 수: 3 (최근 30일)
Tim Schaller
Tim Schaller 2022년 11월 15일
답변: Torsten 2022년 11월 15일
Hi there,
my problem is, that i need the 3D Plot from down below as a SURF, but the way I thought i would need to do it, does not work at all.
So i need it to look like my 3D plot, but not just the lines, I also need the "surface".
I hope you get, what my intention is, and that somebody can help me.
Thnaks in advance.
n = 3;
n1 = n-1;
a = 20;
b = 10;
P = [0 b;0 0;a 0];
T = 15;
H = 8;
R = 2;
h = 6;
syms t s(t)
B = bernsteinMatrix(n1,t);
bezierCurve = B*P;
s(t) = int(norm(diff(bezierCurve)),0,t);
snum = linspace(0,s(1),T);
for i = 1:T
tnum(i) = vpasolve(snum(i)==s(t),t);
end
px = double(subs(bezierCurve(:,1),t,tnum)).';
py = zeros(T,1);
pz = double(subs(bezierCurve(:,2),t,tnum)).';
normalToCurve = diff(bezierCurve)*[0 1;-1 0];
normalToCurve = normalToCurve/norm(normalToCurve);
newNormalToCurve = [double(subs(normalToCurve(1),t,tnum))' double(subs(normalToCurve(2),t,tnum))'];
newNormalToCurvex = newNormalToCurve(:,1);
newNormalToCurvez = newNormalToCurve(:,2);
%%%%%%%%%%%Obere Linie
for i = 1:T
S = double(s((i-1)/(T-1)));
d = R*(1-S/double(s(1)))+(H/2)*S/double(s(1));
delta(i) = d;
end
delta = delta';
pxnew1 = px+newNormalToCurvex.*delta;
pznew1 = pz+newNormalToCurvez.*delta;
for i = 1:T
S = double(s((i-1)/(T-1)));
rhilfe = (h/2)*S/double(s(1));
r(i) = rhilfe;
end
r = r';
pynew1a = - r;
pynew1b = r;
%%%%%%%%%%Untere Linie
delta = - delta;
pxnew2 = px+newNormalToCurvex.*delta;
pznew2 = pz+newNormalToCurvez.*delta;
pynew2a = pynew1a;
pynew2b = pynew1b;
%%%%%%%%%%seitliche Linien (schwarz)
for i = 1:T
S = double(s((i-1)/(T-1)));
chilfe = R*(1-S/double(s(1)))+(h/2)*S/double(s(1));
c(i) = chilfe;
end
for i = 1:T
S = double(s((i-1)/(T-1)));
lhilfe = H/2*S/double(s(1));
l(i) = lhilfe;
end
l = l';
c = c';
pynew3 = ones(T,1).*c;
pxnew3a = px-newNormalToCurvex.*l;
pxnew3b = px+newNormalToCurvex.*l;
pznew3a = pz-newNormalToCurvez.*l;
pznew3b = pz+newNormalToCurvez.*l;
pynew3a = pynew3;
pynew3b = -pynew3;
%%%%%%%%%%%%4Ecken
%%%vorne links/rechts (magenta)
Rnewx = R*cos(pi/4);
Rnewy = R*cos(pi/4);
for i = 1:T
S = double(s((i-1)/(T-1)));
jhilfe = Rnewx*(1-S/double(s(1)))+(H/2)*S/double(s(1));
j(i) = jhilfe;
end
for i = 1:T
S = double(s((i-1)/(T-1)));
ehilfe = Rnewy*(1-S/double(s(1)))+(h/2)*S/double(s(1));
e(i) = ehilfe;
end
j = j';
e = e';
pxnew4 = px+newNormalToCurvex.*j;
pznew4 = pz+newNormalToCurvez.*j;
pynew4a = -ones(T,1).*e;
pynew4b = ones(T,1).*e;
%%%%%vorne links/recht(grün)
pxnew5 = px-newNormalToCurvex.*j;
pznew5 = pz-newNormalToCurvez.*j;
pynew5a = pynew4a;
pynew5b = pynew4b;
%%%%%%%%%%PLOTS
plot3(px,py,pz,'b-')
axis equal
axis tight
grid on
hold on
plot3(pxnew1,pynew1a,pznew1,'r-')
plot3(pxnew1,pynew1b,pznew1,'r-')
plot3(pxnew2,pynew1a,pznew2,'r-')
plot3(pxnew2,pynew1b,pznew2,'r-')
plot3(pxnew3a,pynew3a,pznew3a,'k-')
plot3(pxnew3b,pynew3a,pznew3b,'k-')
plot3(pxnew3a,pynew3b,pznew3a,'k-')
plot3(pxnew3b,pynew3b,pznew3b,'k-')
plot3(pxnew4,pynew4a,pznew4,'m-')
plot3(pxnew4,pynew4b,pznew4,'m-')
plot3(pxnew5,pynew5a,pznew5,'g-')
plot3(pxnew5,pynew5b,pznew5,'g-')
hold off
pxgesamt = [px;pxnew1; pxnew1; pxnew2; pxnew2; pxnew3a;pxnew3b;pxnew3a;pxnew3b;pxnew4; pxnew4; pxnew5; pxnew5];
pygesamt = [py;pynew1a;pynew1b;pynew2a;pynew2b;pynew3a;pynew3a;pynew3b;pynew3b;pynew4a;pynew4b;pynew5a;pynew5b];
pzgesamt = [pz;pznew1; pznew1; pznew2; pznew2; pznew3a;pznew3b;pznew3a;pznew3b;pznew4; pznew4; pznew5; pznew5];
pgesamt = [pxgesamt pygesamt pzgesamt];
surf([pxgesamt pygesamt pzgesamt]) %%%% that obviously does not work

답변 (1개)

Torsten
Torsten 2022년 11월 15일
Given arrays x,y and z where the x,y values are not on a regular grid, you might want to try ScatteredInterpolant first
followed by surf or mesh.

카테고리

Help CenterFile Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by