Determine point position regarding a line
古いコメントを表示
Hi Matlab experts,
I was wondering if anyone would have an idea on how to determine the position (right or left) of a point (in 2D) regarding a line (a segment of a line if we want to be precise) that I have extracted using 'improfile'.
Here's what I've tried:
[cx,cy,c] = improfile(label,xi,yi,j-y_cc); % extracting my line segment
m = [cx(1) cy(1)];
n = [cx(end) cy(end)];
coeff = [[1; 1] m(:)]\n(:); %find the slope and the intercept
for ii = 1:256
for jj = 256:-1:1
if label(ii,jj,k) == 11 || label(ii,jj,k) == 12
pos = sign((n(1) - m(1)) * (jj - m(2)) -...
(n(2) - m(1)) * (ii - m(1)));
%test = jj-ii*coeff(1)-coeff(2); % I have tried looking at the sign of this too
if pos <= 0
labelvst_l(ii,jj,k) = 1;
end
end
end
end
I would be very grateful if anyone could help with this! Thank you
Ismail
回答 (2 件)
KSSV
2016 年 10 月 28 日
0 投票
If (x1,y1) and (x2,y2) are two points P1,P2. You can decide which point comes first by calculating difference between x coordinates i.e (x2-x1). If (x2-x1) is +ve P1 comes first and then P2. If (x2-x1) is negative P2 comes first and then P1.
2 件のコメント
Ismail Koubiyr
2016 年 10 月 28 日
KSSV
2016 年 10 月 28 日
It is a easy task. Refer the below link.
Morteza Adl
2022 年 4 月 22 日
0 投票
You can use cross product.
カテゴリ
ヘルプ センター および File Exchange で Creating and Concatenating Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!