How do I plot random lines, condition : lines cannot intersect each other? Lines can not intersect the boundary box?

조회 수: 1 (최근 30일)
How do I plot random lines in a boundary box?
condition : lines cannot intersect each other?
Lines can not intersect the boundary box?
  댓글 수: 3
Bijaya Bhattarai
Bijaya Bhattarai 2020년 4월 22일
My code is like this;
suggest me the right code as this is showing error.
rectX = [0.1 0.1 0.9 0.9];
rectY = [0.1 0.5 0.5 0.1];
rect = polyshape(rectX,rectY);
% initialize a figure for display purposes
figure(1);clf
Foundblock = false;
while Foundblock == false
ylim([-1.5,1.5]); %Sets y range based on...
xlim([-1.5,1.5]); %Sets x range based on...
grid on; %Create a grid in the background of plot
hold on
plot(rect);
i=1;
for i = 1:3
X1 = [x1o(i) x1i(i)];
Y1 = [y1o(i) y1i(i)];
h1o = plot(X1, Y1,'k','linewidth',0.1);
pause(0.0001);
delete(h1o);
b1x = x1i(i);
b1y = m1*b1x+c1;
if abs(b1y - y1i(i)) < tol
Foundblock = true;
break
end
b1x = x1o(i);
b1y = m1*b1x+c1;
if (b1y - y1o(i)) < tol
Foundblock = true;
break
else
end
end
end
hold off
Walter Roberson
Walter Roberson 2020년 4월 22일
X1 = [x1o(i) x1i(i)];
Y1 = [y1o(i) y1i(i)];
x1o and x1i and y1o and y1i are not defined, and not documented as to what they might be.
I do not see any calls to random routines so I suspect you need to put in some calls to generate random lines.
Your code appears to be looping until it finds the first intersection and then stopping immediately ?

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Random Number Generation에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by