Finding index between two parallel lines

1 次查看(过去 30 天)
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