Effacer les filtres
Effacer les filtres

Finding index between two parallel lines

4 vues (au cours des 30 derniers jours)
wave_buoys
wave_buoys le 10 Mar 2019
Modifié(e) : wave_buoys le 10 Mar 2019
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 commentaires
Star Strider
Star Strider le 10 Mar 2019
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 le 10 Mar 2019
Modifié(e) : wave_buoys le 10 Mar 2019
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

Connectez-vous pour commenter.

Réponse acceptée

darova
darova le 10 Mar 2019
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 commentaire
wave_buoys
wave_buoys le 10 Mar 2019
Modifié(e) : wave_buoys le 10 Mar 2019
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.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Elementary Polygons dans Help Center et File Exchange

Produits


Version

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by