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

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

3 comentarios

Are the lines of fixed length, or fixed orientation? Or is there a fixed distribution of, such as "half of the lines should be length 5, 1/4 should be of length 4, and 1/4 should be of length 3" ?
The question of fixed distribution is important because there are three major approaches for this kind of problem:
  1. Rejection method. You try a location with a known size and known orientation, and if it does not fit right there, you reject the attempt and try another random configuration. As the area gets more full, you can end up taking a long time to find new locations. This approach is not smart about placements, and figuring out whether to give up yet can be tricky, but it can make some guarantees about sizes
  2. Fitting method. You try a location with a known size and known orientation, and if it happens to work, then you use it. But if it does not work, then you look at a particular point such as the center point of the line, and see if it is occupied or not; if it is occupied, you go back to try another location. But if the center point is not occupied, then you try other orientations; or you figure out how long of a line you could put in at that location and "shrink" appropriately. You figure out what will fit at the location, and you go with that. This approach can be much smarter about placements, taking less time to execute, but it does is unlikely to fit any particular distribution of sizes. In particular, the number of small lines you end up with, will be much greater than the number of long lines.
  3. Dynamics method. You toss a bunch of objects into the area one at a time, and each time it would not normally fit, treat it as pushing on existing objects -- which in turn push on other objects, and the wall, and things push back, until eventually enough has moved relative to each other that everything fits and has stopped moving. There are related methods based upon "shaking" the container until everything fits. This approach can make some guarantees about sizes, but the motion calculations can take a bit of time.
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
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 ?

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Random Number Generation en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 22 de Abr. de 2020

Comentada:

el 22 de Abr. de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by