フィルターのクリア

How to plot rectangular footprint around existing random data?

3 ビュー (過去 30 日間)
Larissa Perez
Larissa Perez 2018 年 12 月 4 日
コメント済み: KSSV 2018 年 12 月 7 日
This is the code which will generate random storm track length. Now, I have to plot just rectangtular footprint area around each storm track length. Here, storm track length will be the central width of the rectangle. The image below illustrates what I'd like to do.
Many thanks!!
N = 50; % Number of events
X = 50; Y = 50;
P1x = rand(N,1) * X; P1y = rand(N,1) * Y ; % initial point
L = lognrnd(2,0.7,[N,1]); % Sample track length
Theta = mod(normrnd(90,15,[N,1]),360); % Storm track bearing direction
dx = L.*cos(deg2rad(Theta - 90)); dy = L.*sin(deg2rad(Theta - 270));
P2x = P1x + dx; P2y = P1y + dy; % Final point
plot([0 X X 0 0],[0 0 Y Y 0]); hold on
plot(P1x,P1y,'ro'); plot([P1x P2x]',[P1y P2y]','-')
xlabel('X [km]'); ylabel('Y [km]');
xlim([-X/4 1.25*X]); ylim([-Y/4 1.25*Y])
xx.png

採用された回答

KSSV
KSSV 2018 年 12 月 4 日
N = 50; % Number of events
X = 50; Y = 50;
P1x = rand(N,1) * X; P1y = rand(N,1) * Y ; % initial point
L = lognrnd(2,0.7,[N,1]); % Sample track length
Theta = mod(normrnd(90,15,[N,1]),360); % Storm track bearing direction
dx = L.*cos(deg2rad(Theta - 90)); dy = L.*sin(deg2rad(Theta - 270));
P2x = P1x + dx; P2y = P1y + dy; % Final point
plot([0 X X 0 0],[0 0 Y Y 0]); hold on
plot(P1x,P1y,'ro');
plot([P1x P2x]',[P1y P2y]','-')
xlabel('X [km]'); ylabel('Y [km]');
xlim([-X/4 1.25*X]); ylim([-Y/4 1.25*Y])
%% Draw rectangles
Vx = [P1x P2x]' ;
Vy = [P1y P2y]' ;
t = 1./2 ;
% Loop to get normals
for i = 1:size(Vx,2)
N=LineNormals2D([Vx(:,i) Vy(:,i)]') ;
C = [[Vx(:,i) Vy(:,i)]+t*N ;
[Vx(:,i) Vy(:,i)]-t*N] ;
idx = boundary(C(:,1),C(:,2)) ;
plot(C(idx,1),C(idx,2),'b')
end
YOu can download the function LineNormals2D from the link.
  2 件のコメント
Larissa Perez
Larissa Perez 2018 年 12 月 7 日
Thank you so much for your help! :)
KSSV
KSSV 2018 年 12 月 7 日
thank you is accepting and voting the answer....
TSLA EJ

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeAnnotations についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by