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
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 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