Storm motion over a catchment - fill matrix in a generic direction

Hi everybody,
i'd like to simulate motion of a storm with a specific direction over a catchment, with the goal to individuate at any time-step the catchment's cells covered by the storm. (the storm is supposed to cover the entire catchment at the end of the process)
My idea was to start with a generic catchment surface, represented by a matrix C=zeros(m,n). then i assigned a ratio, rows(dm)/column(dn), that represent the storm direction (i want to control the direction and also the speed) i had the intended to expand this ration over the basin as show in the figure below, but i'm I am having some troubles.
i report the part of the code that i had written (is incomplete and does not work as i want, but maybe can help to understand how i had set up (maybe wrong) the problem ). I will appreciate any help or advice.
thanks
% %
C=zeros(100,100); %are of interest
%
% individuate direction by defining a ratio between rows and column dm/dn
dm = 1; %number of cells along rows
dn = 1; %number of cells along columns
%
v = 1 ;% scale factor for storm velocity
t = 20;% time step of storm passage simulation
%
ST= zeros(size(C,1),size(C,2),t) ; %storm matrix preallocation
%
for k=1:t
%
ST( 1 , 1:dn*k , k ) = 1;
ST( 1:dm*k , 1 , k ) = 1;
% ?????
% ?????
% ?????
end

 채택된 답변

Chad Greene
Chad Greene 2015년 5월 24일
How's this?
[X,Y] = meshgrid(1:200,1:200);
t = 1:20;
x0 = 0.2*rand(size(t));
y0 = 0.3*rand(size(t));
r = 20*t + 10*rand(size(t));
NOP=100; % number of points in circle
ItHasRained = zeros(size(X));
h1 = imagesc(ItHasRained);
caxis([0 1])
colormap([0 0 0; 0.5843 0.8157 0.9882])
hold on
axis([0 200 0 200])
cb = colorbar;
set(cb,'ytick',[0 1],'yticklabel',{'dry';'wet'})
for ti = t
x = x0(ti)+r(ti).*cos( 2*pi/NOP*(1:NOP));
y = y0(ti)+r(ti).*sin( 2*pi/NOP*(1:NOP));
ItHasRained(inpolygon(X,Y,x,y))=1;
set(h1,'cdata',ItHasRained)
h2 = plot(x,y,'r-','linewidth',2);
drawnow
pause(.05)
delete(h2)
end

댓글 수: 1

Thank you Chad! i'll try to implement your code, that seems wonderful for my goal! I will report the progress as soon as possible!

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Walter Roberson
Walter Roberson 2015년 5월 24일

0 개 추천

In order to travel through the matrix in a given direction, you should have a look at Bresenham's Line Algorithm. Chad's Answer is fine but it deals with plotting not with individual entries in a matrix; it is easy to get off of a straight line when you have to quantize down to individual locations.
I posted a formulation that does not require sin() and cos() a couple of hours ago here . It creates floating point outputs and so has some quantization difficulties; however, if you keep the values in floating point and round() them then you can get to indices. Be cautioned, though, that Bresenham's Algorithm produces straighter lines than working with floating point and rounding to integers.

댓글 수: 1

Thank you Walter! never heard about Bresenham's Line Algorithm, it seems an interesting solution! i'll study it and try to implement it,i'll post any results i'll get as soon as possible. bye!

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Oceanography and Hydrology에 대해 자세히 알아보기

질문:

2015년 5월 24일

댓글:

2015년 5월 25일

Community Treasure Hunt

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

Start Hunting!

Translated by