How to find the distance between one slope and several points?
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Beibit Sautbek
le 21 Juil 2016
Réponse apportée : Azzi Abdelmalek
le 21 Juil 2016
I have slope AB, where
A=[x1,y1], B=[x2,y2], and point C=[x0,y0].
In order to find the distance between the point C and slope AB, I have used the formula below:
d=(abs(((x2-x1)*(y1-y0))-((x1-x0)*(y2-y1)))/(sqrt((x2-x1)^2+(y2-y1)^2)));
I can find the distance between slope and one point, but If I have several points, I have a problem in result.
For example:
I have a matrix A as below, where the first row represents A=[x1,y1], and the last row represents B=[x2,y2]:
A =
2 2
3 1
5 4
7 8
10 2
In matrix A, rows 2,3,4 represent 3 different points.
So I need to find a distance between slope and 3 points.
Actually, I did this code, but the result shows 4 values instead of 3 values.
l=length(A);
x1=A(1,1); y1=A(1,2);
x2=A(l,1); y2=A(l,2);
for i=2:l-1
x(i)=A(i,1);
y(i)=A(i,2);
d(i)=(abs(((x2-x1)*(y1-y(i))-((x1-x(i))*(y2-y1)))/(sqrt((x2-x1)^2+(y2-y1)^2))));
end
Could anyone check my code or help to get necessary answer?
0 commentaires
Réponse acceptée
Azzi Abdelmalek
le 21 Juil 2016
x0=A(2:4,1)
y0=A(2:4,2)
d=(abs(((x2-x1).*(y1-y0))-((x1-x0).*(y2-y1)))./(sqrt((x2-x1)^2+(y2-y1)^2)));
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!