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!
