Generate Random Number inside a closed area
Mostrar comentarios más antiguos
Hi,
There is a closed area, as figure1.We wanna have random number inside it.

figure1. An Area with defined boundry poinst.
Since Code has many different layers, I prefer not to use "WHILE" like below. ("Data" is Attached)
load('Data');
in=0;
while ~in
Point(1)=unifrnd( min(x),max(x) );
Point(2)=unifrnd( min(y),max(y) );
in=inpolygon(Point(1),Point(2),x,y);
end
plot(x,y,Point(1),Point(2),'^');
Do you know any ready-to-go command which takes Boundary of a closed area, and gives a random point within it?
Thanks for your helping. <3
Respuesta aceptada
Más respuestas (2)
Dimitris Kalogiros
el 5 de Oct. de 2019
0 votos
Run your code many times and store the resulting point ( variable Point) into a file. Then every time you need a random point from the wanted area, you can have you choose randomly a point from this file.
1 comentario
Armin Mashhadi
el 5 de Oct. de 2019
Image Analyst
el 5 de Oct. de 2019
0 votos
I don't think there is a built in function to do that. I think your strategy of using inpolygon() until you get a point inside is what I'd do.
Categorías
Más información sobre Computational Geometry en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!







