how do i merge the first and second cylinder surface?

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=-1;%shape parameter lambda
B2=-1;%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];
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;
does anyone know how do i merge the two cylinders? i attached the code above. thank you!

 Accepted Answer

Hello NurFadhilah,
I believe this could be solved by substracting the difference in height between the second and third surfaces from Z2 and Z3. Please see attached screenshot. This could be implemented in the code as shown in variables Z2 and Z3 below.
Z2 = [z9 z12]-0.09031;
Z3 =[z12 z9]-0.09031;
Hope this helps!

2 Comments

thank you, this helps! but may i know what's the formula to get the value 0.09031 please?
Hi NurFadhilah! The difference between the heights of the second and third surfaces is equal to 0.09031. So if you subtract this value from each height (Z2 and Z3), the two cylinders will merge.

Sign in to comment.

More Answers (0)

Categories

Community Treasure Hunt

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

Start Hunting!