Generate a Random Point inside a box/plane
Mostrar comentarios más antiguos
- Let's say, I have coordinates of two points as (p,q) and (x,y). I want to generate a random point within the plane bounded by these two points. How do I do that?
- Simialrly, I have coordinates of two points in 3D-space as (p,q,r) and (x,y,z). I want to generate a random point within the box bounded by these two points. How do I do that?
Respuesta aceptada
Más respuestas (1)
A = [0 0] ; % (p,q)
B = [1 1] ; % (x,y)
a = 50;
b = 100;
r = (b-a).*rand(1000,1) + a;
x = (B(1)-A(1))*rand(100,1)+A(1) ;
y = (B(2)-A(2))*rand(100,1)+A(2) ;
box = [A ; B(1) A(2) ; B ; A(1) B(2)] ;
patch(box(:,1),box(:,2),'y')
hold on
plot(x,y,'.r')
Categorías
Más información sobre Random Number Generation 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!
