Determine point position regarding a line
6 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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
0 comentarios
Respuestas (2)
KSSV
el 28 de Oct. de 2016
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.
Ver también
Categorías
Más información sobre Annotations en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!