필터 지우기
필터 지우기

Find which side of a line is my point

조회 수: 9 (최근 30일)
Clementine Bodin
Clementine Bodin 2022년 12월 12일
댓글: Clementine Bodin 2022년 12월 12일
Hello ,
I'm looking for a simple way to know where C or D are in relation to the line AB
I already computed their distance to line AB but it is absolute so I don't know in which direction they are.
Would someone have a solution for this ? Ideally to obtain a negative distance for point C and positive one for point D
I tried computing coeff d=(x−x1)(y2−y1)−(y−y1)(x2−x1) but it's not working well
Thanks a lot

채택된 답변

Bora Eryilmaz
Bora Eryilmaz 2022년 12월 12일
편집: Bora Eryilmaz 2022년 12월 12일
You can use the sign of the z-term of the cross product of the vectors defining the line and the points of interest:
vAB = [3 2 0]; % Vector from A to B, or anywhere along the line
vC = [5 2 0]; % From origin to C
vD = [2 4 0]; % From origin to D
X = cross(vAB, vC);
sign(X(3)) % Below the line when negative
ans = -1
Y = cross(vAB, vD);
sign(Y(3)) % Above the line when positive
ans = 1
  댓글 수: 3
Bora Eryilmaz
Bora Eryilmaz 2022년 12월 12일
편집: Bora Eryilmaz 2022년 12월 12일
vAb = [xb-xa, yb-ya, 0]
vC = [xc, yc, 0]
You don't need the point of intersection. You need the coordinates of C and D.
Clementine Bodin
Clementine Bodin 2022년 12월 12일
Ok got it it seems to work now !! thank you so much

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Linear Algebra에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by