![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/392423/image.png)
Generate some points on the plane restricted by 3 points (triangle)
1 回表示 (過去 30 日間)
古いコメントを表示
Assume that
are the vertices of a triangle in space. How can i generate some points on this triangle?
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/392373/image.png)
0 件のコメント
採用された回答
Ameer Hamza
2020 年 10 月 26 日
編集済み: Ameer Hamza
2020 年 10 月 26 日
This is one of the way
n = 500; % number of random points
p1 = [1 1 2];
p2 = [5 7 3];
p3 = [8 2 1];
ps = [p1; p2; p3];
p12 = p2-p1;
p23 = p3-p2;
P = [p12; p23];
x = sqrt(rand(500, 1));
x = [x x.*rand(500, 1)];
P_new = x*P+p1;
ax = axes();
hold(ax);
view(3);
grid(ax);
plot3(ps(:,1), ps(:,2), ps(:,3), '+', 'MarkerSize', 10, 'LineWidth', 2)
plot3(P_new(:,1), P_new(:,2), P_new(:,3), 'r+', 'MarkerSize', 5, 'LineWidth', 1)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/392423/image.png)
その他の回答 (1 件)
Bruno Luong
2020 年 10 月 26 日
編集済み: Bruno Luong
2020 年 10 月 26 日
Another method:
n = 1000; % number of random points
p1 = [1 1 2];
p2 = [5 7 3];
p3 = [8 2 1];
w = -log(rand(3,n));
xyz = [p1; p2; p3].' * (w./sum(w));
plot3(xyz(1,:),xyz(2,:),xyz(3,:),'.')
参考
カテゴリ
Help Center および File Exchange で Graphics Performance についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!