Generate a Random Point inside a box/plane
이전 댓글 표시
- 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?
채택된 답변
추가 답변 (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')
카테고리
도움말 센터 및 File Exchange에서 Random Number Generation에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
