how to merge two cylinder surfaces?

2 visualizaciones (últimos 30 días)
NurFadhilah Samsuddin
NurFadhilah Samsuddin el 30 de Dic. de 2020
Editada: KALYAN ACHARJYA el 30 de Dic. de 2020
hi, i really need help with merging the two surfaces. i would appreciate it if anyone could point out what i did wrong with my code. the picture attachment below shows the cylinder generated, however they won't merge and i have no idea which part of my code i have to fix. thank you.
clc
clear all
close all
%control point for first surface
P0 = [1 0 0]; P1 = [1 2 0]; P2 = [2 2 0]; P3 = [2 0 0];
P4 = [1 0 1]; P5 = [1 2 1]; P6 = [2 2 1]; P7 = [2 0 1];
P8 = [1 0 2]; P9 = [1 2 2]; P10 = [2 2 2]; P11 = [2 0 2];
P12 = [1 0 3]; P13 = [1 2 3]; P14 = [2 2 3]; P15 = [2 0 3];
phi=1;%scaling factor
B1=0;%shape parameter lambda
B2=0;%shape parameter miu
G17=phi*((2+B1)/(2+B2))*(P3-P2)+P3
G21=phi*((2+B1)/(2+B2))*(P7-P6)+P7
G25=phi*((2+B1)/(2+B2))*(P11-P10)+P11
G29=phi*((2+B1)/(2+B2))*(P15-P14)+P15
%control point for second surface
P3; G17; P18 = [1 -2 0]; P19 = [1 0 0];
P7; G21; P22 = [1 -2 1]; P23 = [1 0 1];
P11; G25; P26 = [1 -2 2]; P27 = [1 0 2];
P15; G29; P30 = [1 -2 3]; P31 = [1 0 3];
%control point for third surface
P12; P13; P14; P15;
P32 = [1 0 4];P33 = [1 2 4]; P34 = [2 2 4]; P35 = [2 0 4];
P36 = [1 0 5];P37 = [1 2 5]; P38 = [2 2 5]; P39 = [2 0 5];
P40 = [1 0 6];P41 = [1 2 6]; P42 = [2 2 6]; P43 = [2 0 6];
G44=phi*((2+B1)/(2+B2))*(P15-P14)+P15
G45=phi*((2+B1)/(2+B2))*(P35-P34)+P35
G46=phi*((2+B1)/(2+B2))*(P39-P38)+P39
G47=phi*((2+B1)/(2+B2))*(P43-P42)+P43
%control point for fourth surface
P15;G44;P48 = [1 -2 3]; P49 = [1 0 3];
P35;G45;P50 = [1 -2 4]; P51 = [1 0 4];
P39;G46;P52 = [1 -2 5]; P53 = [1 0 5];
P43;G47;P54 = [1 -2 6]; P55 = [1 0 6];
Gx=[P0(1) P1(1) P2(1) P3(1);P4(1) P5(1) P6(1) P7(1);P8(1) P9(1) P10(1) P11(1);P12(1) P13(1) P14(1) P15(1)];
Gy=[P0(2) P1(2) P2(2) P3(2);P4(2) P5(2) P6(2) P7(2);P8(2) P9(2) P10(2) P11(2);P12(2) P13(2) P14(2) P15(2)];
Gz=[P0(3) P1(3) P2(3) P3(3);P4(3) P5(3) P6(3) P7(3);P8(3) P9(3) P10(3) P11(3);P12(3) P13(3) P14(3) P15(3)];
Gx1=[P3(1) G17(1) P18(1) P19(1);P7(1) G21(1) P22(1) P23(1);P11(1) G25(1) P26(1) P27(1);P15(1) G29(1) P30(1) P31(1)];
Gy1=[P3(2) G17(2) P18(2) P19(2);P7(2) G21(2) P22(2) P23(2);P11(2) G25(2) P26(2) P27(2);P15(2) G29(2) P30(2) P31(2)];
Gz1=[P3(3) G17(3) P18(3) P19(3);P7(3) G21(3) P22(3) P23(3);P11(3) G25(3) P26(3) P27(3);P15(3) G29(3) P30(3) P31(3)];
Gx2=[P12(1) P13(1) P14(1) P15(1);P32(1) P33(1) P34(1) P35(1);P36(1) P37(1) P38(1) P39(1);P40(1) P41(1) P42(1) P43(1)];
Gy2=[P12(2) P13(2) P14(2) P15(2);P32(2) P33(2) P34(2) P35(2);P36(2) P37(2) P38(2) P39(2);P40(2) P41(2) P42(2) P43(2)];
Gz2=[P12(3) P13(3) P14(3) P15(3);P32(3) P33(3) P34(3) P35(3);P36(3) P37(3) P38(3) P39(3);P40(3) P41(3) P42(3) P43(3)];
Gx3=[P15(1) G44(1) P48(1) P49(1);P35(1) G45(1) P50(1) P51(1);P39(1) G46(1) P52(1) P53(1);P43(1) G47(1) P54(1) P55(1)];
Gy3=[P15(2) G44(2) P48(2) P49(2);P35(2) G45(2) P50(2) P51(2);P39(2) G46(2) P52(2) P53(2);P43(2) G47(2) P54(2) P55(2)];
Gz3=[P15(3) G44(3) P48(3) P49(3);P35(3) G45(3) P50(3) P51(3);P39(3) G46(3) P52(3) P53(3);P43(3) G47(3) P54(3) P55(3)];
N=20;
t=(1:N)'/N;
p=(pi/2)*t;
T=[p.^0 sin(p) (sin(p).^2) (sin(p).^3) cos(p) (cos(p).^2) (cos(p).^3)];
A=[1 0 0 1;
-(B1+2) (2+B1) 0 0;
((2*B1)+1) -(2+2*B1) 0 0;
-B1 B1 0 0;
0 0 2+B2 -(B2+2);
0 0 -((2*B2)+2) ((2*B2)+1);
0 0 B2 -B2];
TT=transpose(T);
AA=transpose(A);
z1 = T*A*Gx*AA*TT;
z2 = T*A*Gy*AA*TT;
z3 = T*A*Gz*AA*TT;
z4 = T*A*Gx1*AA*TT;
z5 = T*A*Gy1*AA*TT;
z6 = T*A*Gz1*AA*TT;
z7 = T*A*Gx2*AA*TT;
z8 = T*A*Gy2*AA*TT;
z9 = T*A*Gz2*AA*TT;
z10 = T*A*Gx3*AA*TT;
z11 = T*A*Gy3*AA*TT;
z12 = T*A*Gz3*AA*TT;
X = [z1 z4];
Y = [z2 z5];
Z = [z3 z6];
X1 =[z4 z1];
Y1 =[z5 z2];
Z1 =[z6 z3];
X2 = [z7 z10];
Y2 = [z8 z11];
Z2 = [z9 z12];
X3 =[z10 z7];
Y3 =[z11 z8];
Z3 =[z12 z9];
Z4 = [z3 z7];
Z5 = [z6 z10];
scatter3([P0(1),P1(1),P2(1),P3(1),P4(1),P5(1),P6(1),P7(1),P8(1),P9(1),P10(1),P11(1),P12(1),P13(1),P14(1),P15(1)],[P0(2),P1(2),P2(2),P3(2),P4(2),P5(2),P6(2),P7(2),P8(2),P9(2),P10(2),P11(2),P12(2),P13(2),P14(2),P15(2)],[P0(3),P1(3),P2(3),P3(3),P4(3),P5(3),P6(3),P7(3),P8(3),P9(3),P10(3),P11(3),P12(3),P13(3),P14(3),P15(3)],'filled','MarkerFaceColor',[1 0 0]);hold on
scatter3([P3(1),G17(1),P18(1),P19(1),P7(1),G21(1),P22(1),P23(1),P11(1),G25(1),P26(1),P27(1),P15(1),G29(1),P30(1),P31(1)],[P3(2),G17(2),P18(2),P19(2),P7(2),G21(2),P22(2),P23(2),P11(2),G25(2),P26(2),P27(2),P15(2),G29(2),P30(2),P31(2)],[P3(3),G17(3),P18(3),P19(3),P7(3),G21(3),P22(3),P23(3),P11(3),G25(3),P26(3),P27(3),P15(3),G29(3),P30(3),P31(3)],'filled','MarkerFaceColor',[1 0 0]);hold on
surf(X,Y,Z)
hold on;
surf(X1,Y1,Z1)
%surf(z1,z2,z3);
hold on;
surf(X2,Y2,Z2);
hold on;
surf(X3,Y3,Z3);
hold on;

Respuestas (1)

KALYAN ACHARJYA
KALYAN ACHARJYA el 30 de Dic. de 2020
Editada: KALYAN ACHARJYA el 30 de Dic. de 2020
Manually: Here I just subtract the adjusted z data to fill the gap, hence z values are shifted towards lowerside by the amount.
% Rest code same
surf(X2,Y2,Z2-0.3);
hold on;
surf(X3,Y3,Z3-0.3);

Categorías

Más información sobre Surface and Mesh Plots en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by