Finding index between two parallel lines

조회 수: 1 (최근 30일)
wave_buoys
wave_buoys 2019년 3월 10일
편집: wave_buoys 2019년 3월 10일
Hello,
I have bathymetry data (an intuition is attached here) which is stored in a regular 10m-resolution grid with the following limits:
  • In the x-axis: xmin:10:xmax. This contains 3039 columns
  • In the y-axis: ymin:10:ymax. This forms 1195 rows
  • The depth is Z matrix whose size is equal to 1195x 3039;
And I have 2 parallel lines crossing this bathymetry with the following information:
  • Line 1 is defined as points (x1,y1) and (x2,y2)
  • Line 2 is defined as points (x3,y3) and (x4,y4)
My task is to find indices between these two lines. Could you please help to solve this?
Many thanks
T
  댓글 수: 2
Star Strider
Star Strider 2019년 3월 10일
My task is to find indices between these two lines.
‘Index’ means different things in different contexts (e.g. matrix, book, etc.). How do you define it here?
wave_buoys
wave_buoys 2019년 3월 10일
편집: wave_buoys 2019년 3월 10일
Hi, Star Strider,
I have updated the intuition as an photo attached. The indices are defined based on the matrix Z (water depth) which is bounded by xmin, xmax, ymin, ymax.
The area to find indices is a parallelogram, so it might be more tricky than a square or rectangular shape. In other words, I can't use idx=find (x>= xmin & x<= xmax & y>=ymin & x<=ymax) to define the indices in the parallelogram region.
Thanks

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

채택된 답변

darova
darova 2019년 3월 10일
You can use inpolygon
clc, clear
xmin = 50;
xmax = 551;
ymin = -35;
ymax = -800;
y1 = ymax + 150;
y4 = ymin - 150;
k_up = (y1 - ymin)/(xmax-xmin);
k_down = (ymax - y4)/(xmax-xmin);
cla, hold on
for x = xmin:10:xmax
y_start = ceil(y1 - x*k_up);
y_end = floor(ymax - x*k_down);
for y = y_start:-10:y_end
plot(x,y,'.r')
end
end
hold off
  댓글 수: 1
wave_buoys
wave_buoys 2019년 3월 10일
편집: wave_buoys 2019년 3월 10일
Hi darova ,
Thanks for the code.
it looks you are on the right track. Using inpolygon works for me! Here is my approach:
polx=[2908,2943,2938,2916]; % define x-coordinates for the polygon
poly=[5757,5760,5759,5756]; % define y-coordinates for the polygon
% XB, YB: two-dimensional matrices defined by meshgrid(xmin:10:xmax,ymin:10:ymax);
[in,out]=inpolygon(XB,YB,polx,poly); % this returns logical values
nums_idx = double(in); % then I converted into numbers
idxall=find(nums_idx); % find non-zero values
XC=XB(idxall); YC=YB(idxall); % this returns to indices inside the polygon!
Thanks for your help with suggesting to use inpolygon again.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Mathematics and Optimization에 대해 자세히 알아보기

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by