generate random point from within three points

3 ビュー (過去 30 日間)
Hassan
Hassan 2013 年 10 月 22 日
コメント済み: Image Analyst 2013 年 10 月 23 日
if i have three points P1=(x1,y1),P2=(x2,y2),P3=(x3,y3). how can i generate a random point within them .
Thanks,
  2 件のコメント
Azzi Abdelmalek
Azzi Abdelmalek 2013 年 10 月 22 日
Do you mean inside a triangle?
Hassan
Hassan 2013 年 10 月 22 日
yes

サインインしてコメントする。

回答 (1 件)

Image Analyst
Image Analyst 2013 年 10 月 22 日
One way is to generate random coordinates within the x and y range - this would give a point in a rectangle. Then call inpolygon() to see if that point is inside the triangle. If it is, you're done. Otherwise, try another random point until you get one that is in side the polygon.
  2 件のコメント
Hassan
Hassan 2013 年 10 月 22 日
i think this not a practical solution
Image Analyst
Image Analyst 2013 年 10 月 23 日
And why not? What's wrong with it? It's simple and fast. Anything else, such as using affine transforms, will be far more complicated. I believe even Roger Stafford was okay with the try-and-exclude method for getting random points in a circle, though he did come up with a better analytical method, but a circle is simpler than some arbitrary triangle.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeRandom Number Generation についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by