I want to generate a fixed percent of random points on a straight line joining two points.

2 ビュー (過去 30 日間)
I want to generate 5 percent of the randomly generated numbers in a fixed straight line equation. For example, i have two points (x1, y1) and (x2, y2), and now i have drawn a straight line between the two points, with the help of straight line equation. Now i want 100 random numbers to be generated out of which 5 percent of those random numbers should fall in the straight line that is joined between the two points.
  5 件のコメント
SUSHMA MB
SUSHMA MB 2016 年 8 月 3 日
let the boundary be a square of sides 10m side length.
SUSHMA MB
SUSHMA MB 2016 年 8 月 3 日
Let the
XY_BOUNDARY = [0,70,0,50};
position = [XY_BOUNDARY(2) - XY_BOUNDARY(1); XY_BOUNDARY(4) - XY_BOUNDARY(3)] .* rand(2,1) ...
+ [XY_BOUNDARY(1);XY_BOUNDARY(3)];
In the above code i get a random number within the specified boundary. Now i want the random point position in a specified boundary as well as on the line connecting two points (x1,y1), and (x2,y2)...Please tell me how to do this

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

採用された回答

Torsten
Torsten 2016 年 8 月 3 日
Instead of generating 100 random numbers, use "rand" to generate 5 random numbers on [0:1] and set the points to
lambda=rand(5,1);
x=x1+lambda*(x2-x1);
y=y1+lambda*(y2-y1);
Best wishes
Torsten.
  5 件のコメント
SUSHMA MB
SUSHMA MB 2016 年 8 月 3 日
But can you plz tell me that, if 100 points are their, then how can i make atleast 5 points to appear it on a line
SUSHMA MB
SUSHMA MB 2016 年 8 月 3 日
編集済み: SUSHMA MB 2016 年 8 月 3 日
Let the
XY_BOUNDARY = [0,70,0,50};
position = [XY_BOUNDARY(2) - XY_BOUNDARY(1); XY_BOUNDARY(4) - XY_BOUNDARY(3)] .* rand(2,1) ...
+ [XY_BOUNDARY(1);XY_BOUNDARY(3)];
In the above code i get a random number within the specified boundary. Now i want the random point position in a specified boundary as well as on the line connecting two points (x1,y1), and (x2,y2)...Please tell me how to do this

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

その他の回答 (0 件)

カテゴリ

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