Find which side of a line is my point
9 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Clementine Bodin
am 12 Dez. 2022
Kommentiert: Clementine Bodin
am 12 Dez. 2022
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
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1228832/image.png)
0 Kommentare
Akzeptierte Antwort
Bora Eryilmaz
am 12 Dez. 2022
Bearbeitet: Bora Eryilmaz
am 12 Dez. 2022
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
Y = cross(vAB, vD);
sign(Y(3)) % Above the line when positive
3 Kommentare
Bora Eryilmaz
am 12 Dez. 2022
Bearbeitet: Bora Eryilmaz
am 12 Dez. 2022
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.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Linear Algebra finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!