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
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
Ismail Koubiyr 2016년 10월 28일
Thank you for your answer. The thing is I'm trying to know whether a point P is above or under a line (segment) that is defined by two points Q1 and Q2 that I'm getting from the function 'improfile'

댓글을 달려면 로그인하십시오.

Morteza Adl
Morteza Adl 2022년 4월 22일

0 개 추천

You can use cross product.

카테고리

도움말 센터File Exchange에서 Annotations에 대해 자세히 알아보기

질문:

2016년 10월 27일

답변:

2022년 4월 22일

Community Treasure Hunt

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

Start Hunting!

Translated by