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

11 vues (au cours des 30 derniers jours)
How do I plot random lines in a boundary box?
condition : lines cannot intersect each other?
Lines can not intersect the boundary box?
  3 commentaires
Bijaya Bhattarai
Bijaya Bhattarai le 22 Avr 2020
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 le 22 Avr 2020
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 ?

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Random Number Generation dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by