# Pipe elbow creation using MATLAB code

14 ビュー (過去 30 日間)
Md Mia 2023 年 1 月 5 日
コメント済み: Md Mia 2023 年 2 月 4 日
Hi
I am done with my MATLAB code which creates as many straight pipes I want. However, I want to connect them using pipe elbow looks like below. Any idea how to create this elbow in MATLAB?  ##### 2 件のコメント表示非表示 1 件の古いコメント
Md Mia 2023 年 1 月 23 日

Thanks. Here is the way I tried to model the elbow using MATLAB. My target is to attach two pipes with this 90 degree elbow. At first I modleed a bent curve (basically the center line of the elbow - blue line in the fig below). Now knowing the x,y,z coordiantes of the points on the curve, I created 3d circles along those points and it looks like below. However, when I was trying to connect it with first straight pipe, it's not working. Is there any mistake I am doing during elbow modeling.
%% elbow inputs
pipe_size = 25.4; % in mm
d_outside = 33.4; % in mm
A = 38; % in mm (center-to-end distance) % Ref. 1 (page 16, Table 3)
% long radius elbow is used where radius of curvature is greater than pipe diamter (>= 1.5*pipe diamater)
% For 90° Long Radius elbows, center to end dimension given in dimension tables of ASME B16.9 is same as radius of elbow (Ref. 2)
x1 = 2100; % left_pipe_end_x
y1 = 0.00; % left_pipe_end_yo
x2 = 2138; % right_pipe_end_x
y2 = -38; % right_pipe_end_y
R = 38; % radius of curvature in mm
%% now let's calculate center point (x0,y0)
syms x0 y0
eq1 = R^2-((x0-x1)^2 + (y0-y1)^2);
eq2 = R^2-((x0-x2)^2 + (y0-y2)^2);
sol=solve([eq1,eq2,x0<=x1,y0<=y2],[x0,y0]);
x_c = double(sol.x0)
y_c = double(sol.y0)
%(x0,y0) = (2138,0)
%% other points
x = linspace(x1,x2,50);
x = x';
for i = 1:length(x)
x1 = x(i);
eqa1 = @(y) R^2 - ((x_c-x1)^2 + (y_c-y)^2);
format long g
y_l = [0 -38];
y(i) = fzero(eqa1,y_l);
end
y = y';
final_mat = [x,y];
plot(final_mat(:,1), final_mat(:,2), 'b-', 'LineWidth', 2)
hold on
for i = 1:length(final_mat(:,1))
[x_value{i},y_value{i},z_value{i}] = plotCircle3D ([x(i),y(i),0], [1,0,0], d_outside/2, n_ele_circum);
end
function [x_value,y_value,z_value] = plotCircle3D(center, normal, radius, n_ele_circum)
d_theta = 2*pi/n_ele_circum; % increment size
theta = 0:d_theta:(2*pi-d_theta); % in radian
v=null(normal);
plot3(points(1,:),points(2,:),points(3,:),'r-');
x_value = points(1,:);
y_value = points(2,:);
z_value = points(3,:);
end サインインしてコメントする。

### 採用された回答

John D'Errico 2023 年 1 月 25 日

What is not working? Why do you think it is not working?
I would conjecture that one problem you have is you cannot model a 90 degree elbow as you tried to do. Your circles are drawn always parallel to each other. And that MUST be incorrect.
A second problem is you are drawing only circles. They will have no connection to each other along the length of the elbow. And that two will be a problem. So do this better by drawing a true surface, as what I would call a 2-manifold. Setting it up to follow a curve in space is a good idea.
The nice thing is, this makes it also trivial to generate a series of pipes, because the cylinder code I wrote does not care if the centerline path is a linear segment or a circular arc. For example
[pipe1x,pipe1y,pipe1z] = generalCylinder([-1 1 0;0 1 0],0.25,50);
[pipe2x,pipe2y,pipe2z] = generalCylinder([1 0 0;1 -1 0],0.25,50);
phi = linspace(0,pi/2)';
elbowarcxyz = 1*[cos(phi),sin(phi),zeros(numel(phi),1)];
[elbowx,elbowy,elbowz] = generalCylinder(elbowarcxyz,0.25,50);
H1 = surf(pipe1x,pipe1y,pipe1z);
hold on
H2 = surf(pipe2x,pipe2y,pipe2z);
H3 = surf(elbowx,elbowy,elbowz);
H1.FaceColor = 'b';
H2.FaceColor = 'g';
H3.FaceColor = 'r';
box on
hold off
axis equal I attached generalCylinder to this answer.
Now all you need do is create a centerline path through space, and then use the cylinder code to build the cylinder as a surface that follows that path.
##### 5 件のコメント表示非表示 4 件の古いコメント
Md Mia 2023 年 2 月 4 日
I figured it out and solved it. I found that I made mistake in defining the elbow center. However, thanks for your (@John D'Errico) generalcylinder function. I highly appreciate it.

サインインしてコメントする。

### カテゴリ

Find more on General Applications in Help Center and File Exchange

### Community Treasure Hunt

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

Start Hunting!