How can I remove the lines that are not in the cross section of the annulus?

1 次查看(过去 30 天)
% Declare experimental variables
R1=75; % inner radius
R2=150; % outer radius of pipe cross-section
N=4; % number of devices
% Create arrays and internal variables
r=linspace(R1,R2,200); % array of radial points for temp data
theta=0:360; % array of angles for temp data
alpha=360/N; % spacing for devices
alpha_ar=round([0:alpha:359]); % array of angles for outter devices in R2
alpha_ar2=round([alpha/2:alpha:359]); % array of angles for inner devices in R1
% Mark devices
for d=1:length(alpha_ar)
for f=1:length(alpha_ar2)
x1=R1*cosd(alpha_ar2(d));
y1=R1*sind(alpha_ar2(d));
plot(x1,y1,'rd','MarkerSize',1,'LineWidth',4);
x2=R2*cosd(alpha_ar(f));
y2=R2*sind(alpha_ar(f));
plot(x2,y2,'rd','MarkerSize',1,'LineWidth',4);
end
end
for i=1:length(alpha_ar)
for k=1:length(alpha_ar2)
alpha1=alpha_ar(i); % i = index for alpha1 (device angle)
alpha3=alpha_ar2(k);
j=1; % initialize j, the index for alpha2
while j<=length(alpha_ar)
if j==i % i and j reference different devices...
j=j+1; % if i=j then increment j again
end
if j<=length(alpha_ar)
alpha2=alpha_ar(j); % j = index for alpha2 (device angle)
end
x=[R2*cosd(alpha_ar(i)),R2*cosd(alpha_ar(j)),R1*cosd(alpha_ar2(k)),R1*cosd(alpha_ar2(k))]; % x values of US devices
y=[R2*sind(alpha_ar(i)),R2*sind(alpha_ar(j)),R1*sind(alpha_ar2(k)),R1*sind(alpha_ar2(k))]; % y values of US devices
figure(1);
% add lj line to temperature profile
hold on;
line(x,y,'color','red');
j=j+1; % increment to next transducer
if j==length(alpha_ar) && j==i % increment j again after last
j=j+1; % tao to break out of loop
end
end
end
end
  4 个评论
Rik
Rik 2020-8-3
Question body recovered from Google cache:
% Declare experimental variables
R1=75; % inner radius
R2=150; % outer radius of pipe cross-section
N=4; % number of devices
% Create arrays and internal variables
r=linspace(R1,R2,200); % array of radial points for temp data
theta=0:360; % array of angles for temp data
alpha=360/N; % spacing for devices
alpha_ar=round([0:alpha:359]); % array of angles for outter devices in R2
alpha_ar2=round([alpha/2:alpha:359]); % array of angles for inner devices in R1
% Mark devices
for d=1:length(alpha_ar)
for f=1:length(alpha_ar2)
x1=R1*cosd(alpha_ar2(d));
y1=R1*sind(alpha_ar2(d));
plot(x1,y1,'rd','MarkerSize',1,'LineWidth',4);
x2=R2*cosd(alpha_ar(f));
y2=R2*sind(alpha_ar(f));
plot(x2,y2,'rd','MarkerSize',1,'LineWidth',4);
end
end
for i=1:length(alpha_ar)
for k=1:length(alpha_ar2)
alpha1=alpha_ar(i); % i = index for alpha1 (device angle)
alpha3=alpha_ar2(k);
j=1; % initialize j, the index for alpha2
while j<=length(alpha_ar)
if j==i % i and j reference different devices...
j=j+1; % if i=j then increment j again
end
if j<=length(alpha_ar)
alpha2=alpha_ar(j); % j = index for alpha2 (device angle)
end
x=[R2*cosd(alpha_ar(i)),R2*cosd(alpha_ar(j)),R1*cosd(alpha_ar2(k)),R1*cosd(alpha_ar2(k))]; % x values of US devices
y=[R2*sind(alpha_ar(i)),R2*sind(alpha_ar(j)),R1*sind(alpha_ar2(k)),R1*sind(alpha_ar2(k))]; % y values of US devices
figure(1);
% add lj line to temperature profile
hold on;
line(x,y,'color','red');
j=j+1; % increment to next transducer
if j==length(alpha_ar) && j==i % increment j again after last
j=j+1; % tao to break out of loop
end
end
end
end

请先登录,再进行评论。

采纳的回答

Matt J
Matt J 2020-7-22
figure(1);
% add lj line to temperature profile
hold on;
for ii=0:1
[P1,P2]=deal([x(1+ii);y(1+ii)], [x(2+ii);y(2+ii)]);
fun=@(t) norm(t*P1+(1-t)*P2);
[~,R]=fminbnd(fun,0,1);
if R<R1; continue; end
line([P1(1),P2(1)],[P1(2),P2(2)],'color','red');
end
  3 个评论
Matt J
Matt J 2020-7-22
编辑:Matt J 2020-7-22
These lines
fun=@(t) norm(t*P1+(1-t)*P2);
[~,R]=fminbnd(fun,0,1);
find the distance R of the line segment [P1,P2] to the origin. Based on that, you can test whether the line segment remains within the annulus.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 MATLAB Mobile Fundamentals 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by