MATLAB Answers

3D-Surface between 2 lines.

8 views (last 30 days)
Hi all,
Previously with one of the Mathwork community users' (darova) suggestion we created 3D surfaces on the sphere.
Please find the script below.
Here I have 3 surfaces the one of which (green) is below the other 2 surfaces.
Now, I aim to fill the gap between the top (red) and bottom (green) surfaces by creating an additional surface (i.e. an oblique surface (a slightly tilted surface)).
To make it clearer, in the output image of the attached code one can see 2 lines between the top (red) and bottom (green) surfaces.
I aim to create a surface between those 2 lines in order to close the gap.
I've tried several ways, and also a triangulation method, however, was not successfull.
Could you please make a suggestion on this.
I appreciate the time you spend.
Regards
l1 = [-3.53 -3.16 -3.543 -3.359];
l2 = [-3.16 -3.16 -3.359 -2.807];
l3 = [-3.16 -3.846 -2.807 -2.518];
l4 = [-3.846 -3.925 -2.518 -3.254];
l5 = [-3.925 -3.53 -3.254 -3.543];
ll1 = [-4.05 -4.690 -3.274 -3.395];
ll2 = [-4.690 -4.479 -3.395 -2.728];
ll3 = [-4.479 -4.347 -2.728 -2.597];
ll4 = [-4.347 -3.978 -2.597 -2.545];
ll5 = [-3.978 -4.05 -2.545 -3.274];
c1 = [-4.03 -3.966 -3.229 -2.532];
c2 = [-3.966 -3.872 -2.532 -2.545];
c3 = [-3.872 -3.932 -2.545 -3.229];
c4 = [-3.932 -4.03 -3.229 -3.229];
xl1 = [l1(1) l1(2) l2(2) l3(2) l4(2) l1(1)];
yl1 = [l1(3) l1(4) l2(4) l3(4) l4(4) l1(3)];
xl2 = [ll1(1) ll1(2) ll2(2) ll3(2) ll4(2) ll1(1)];
yl2 = [ll1(3) ll1(4) ll2(4) ll3(4) ll4(4) ll1(3)];
xf = [c1(1) c1(2) c2(2) c3(2)];
yf = [c1(3) c1(4) c2(4) c3(4)];
rf = 6.8;
gd1 = [2;length(xl1);xl1(:);yl1(:)];
dl1 = decsg(gd1);
[p1,e1,t1] = initmesh(dl1,'hmax',0.2);
z1 = sqrt(49 - p1(1,:).^2 - p1(2,:).^2);
ff1.vertices = [p1' z1(:)];
ff1.faces = t1(1:3,:)';
gd2 = [2;length(xl2);xl2(:);yl2(:)];
dl2 = decsg(gd2);
[p2,e2,t2] = initmesh(dl2,'hmax',0.2);
z2 = sqrt(49 - p2(1,:).^2 - p2(2,:).^2);
ff2.vertices = [p2' z2(:)];
ff2.faces = t2(1:3,:)';
gdf = [3;4;xf(:);yf(:)];
dlf = decsg(gdf);
[pf,ef,tf] = initmesh(dlf,'hmax',0.2);
zf = sqrt(47.5 - pf(1,:).^2 - pf(2,:).^2);
ff3.vertices = [pf' zf(:)];
ff3.faces = tf(1:3,:)';
[x,y,z] = sphere(20);
surf(7*x,7*y,7*z,'facecolor','none','edgecolor',[1 1 1]*0.8)
line(xl1,yl1,'linew',2)
h1 = patch(ff1,'facecolor','b');
hold on
%[x,y,z] = sphere(20);
surf(7*x,7*y,7*z,'facecolor','none','edgecolor',[1 1 1]*0.8)
line(xl2,yl2,'linew',2)
h2 = patch(ff2,'facecolor','r');
hold on
%[x,y,z] = sphere(20);
surf(7*x,7*y,7*z,'facecolor','none','edgecolor',[1 1 1]*0.8)
line(xf,yf,'linew',2)
hf = patch(ff3,'facecolor','g');
xfl = [-4.0300 -4.0500 -3.966 -3.978];
yfl = [-3.2290 -3.2740 -2.532 -2.545];
zfl = [zf(1) z2(5) zf(2), z2(4)];
hline1=plot3(([xfl(1) xfl(2)]),([yfl(1) yfl(2)]),([zfl(1) zfl(2)]),'k');
hline2=plot3(([xfl(3) xfl(4)]),([yfl(3) yfl(4)]),([zfl(3) zfl(4)]),'k');
hold on
set(hline1,'linewidth',2)
set(hline2,'linewidth',2)

  0 Comments

Sign in to comment.

Accepted Answer

darova
darova on 4 Jul 2020
what about this?
xf = [xl2(1) xl2(5) xl1(4) xl1(5)];
yf = [yl2(1) yl2(5) yl1(4) yl1(5)];

  3 Comments

Mammadbaghir Baghirzade
Mammadbaghir Baghirzade on 4 Jul 2020
Hi Darova,
Thank you for your reply.
I used the lines you provided, neverheless, it did show any changes.
I need to generate 4 side surfaces from the bottom green surface upto top red and blue surfaces.
darova
darova on 5 Jul 2020
see this
n = 10;
xf1 = linspace(xl2(1), xl2(5), n);
xf2 = linspace(xl1(5), xl1(4), n);
yf1 = linspace(yl2(1), yl2(5), n);
yf2 = linspace(yl1(5), yl1(4), n);
zf11 = sqrt(49 - xf1.^2 - yf1.^2);
zf12 = sqrt(47.5 - xf1.^2 - yf1.^2);
zf21 = sqrt(47.5 - xf2.^2 - yf2.^2);
zf22 = sqrt(49 - xf2.^2 - yf2.^2);
surface([xf1;xf1;xf2;xf2],...
[yf1;yf1;yf2;yf2],...
[zf11;zf12;zf21;zf22],'facecolor','g')
Mammadbaghir Baghirzade
Mammadbaghir Baghirzade on 5 Jul 2020
Thank you Darova,
I appreciate!
Kind regards

Sign in to comment.

More Answers (1)

Mehmed Saad
Mehmed Saad on 4 Jul 2020
Edited: Mehmed Saad on 4 Jul 2020
I have a layman approach for this (The dumb method)
get co-ordinates by cursor
export them to workspace
save it in a variable
Now access all the co-ords
apos = [cursor_info.Position];
hold on,fill3(apos(1:3:end),apos(2:3:end),apos(3:3:end),'r','EdgeColor','none')

  1 Comment

Mammadbaghir Baghirzade
Mammadbaghir Baghirzade on 4 Jul 2020
Hi Mehmed,
Thank you for your reply.
I will check this method, actually at the same time I want to generate triangular meshes on the surface.
However, if that won't work your suggested approach will be the solution.
Regards
Mehmet

Sign in to comment.