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

1 回表示 (過去 30 日間)
Cnell
Cnell 2020 年 7 月 22 日
コメント済み: Rena Berman 2020 年 10 月 12 日
% 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
Rena Berman
Rena Berman 2020 年 10 月 12 日
(Answers Dev) Restored edit

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

採用された回答

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 件のコメント
Cnell
Cnell 2020 年 7 月 22 日
If you have time, could you explain how this works?
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 Center および File ExchangeMATLAB Mobile Fundamentals についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by