フィルターのクリア

how to generate points inside a rectangle not parallel to axis in Matlab

2 ビュー (過去 30 日間)
nadia nadi
nadia nadi 2021 年 10 月 18 日
コメント済み: nadia nadi 2021 年 10 月 18 日
Dear all,
I want to generate points inside a rectangle that is not parallel to the axis and have only the length, width, center, and degree of tilt. of the rectangle. Can any one help me with it please. I'm writing down some of the code. Thank you in advance.
z=[ 34.7814 29.7298 41.9441 28.3367 12.8067];
w=z(1); %width
h=z(2);%length
x=z(3);% center
y=z(4);%center
alpha=z(5); %degree of tilt
xv = [-w/2 w/2 w/2 -w/2 -w/2];
yv = [h/2 h/2 -h/2 -h/2 h/2];
R = [xv;yv];
alpha2=alpha*pi/180;
ct = cos(alpha2);
st = sin(alpha2);
Q = [ct -st;st ct];
XY1 = Q*R;
XY=[XY1(1,:)+x;XY1(2,:)+y];
center=(XY(:,1)+XY(:,3))/2;
  1 件のコメント
nadia nadi
nadia nadi 2021 年 10 月 18 日
Dear Matt,
Thank you for helping me. it works fine.
Best

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

採用された回答

Matt J
Matt J 2021 年 10 月 18 日
編集済み: Matt J 2021 年 10 月 18 日
You mean you want to generate N random points? If so, then,
xy=Q*([length;width].*(rand(2,N)-0.5)) + center(:)
  1 件のコメント
nadia nadi
nadia nadi 2021 年 10 月 18 日
I just needed to change the locations of the width and length [width;length]
best

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

その他の回答 (0 件)

製品


リリース

R2014a

Community Treasure Hunt

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

Start Hunting!

Translated by