Determine point position regarding a line
Afficher commentaires plus anciens
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
Réponses (2)
KSSV
le 28 Oct 2016
0 votes
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 commentaires
Ismail Koubiyr
le 28 Oct 2016
KSSV
le 28 Oct 2016
It is a easy task. Refer the below link.
Morteza Adl
le 22 Avr 2022
0 votes
You can use cross product.
Catégories
En savoir plus sur Annotations dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!