calculate an angle and distance from three points
7 views (last 30 days)
Show older comments
bil bbil
on 10 Mar 2014
Commented: Mansour Attaallah
on 11 Aug 2018
hi...How to calculate an angle and distance from three points? ex P1 = (x=2, y=50) P2 = (x=9, y=40) P3 = (x=5, y=20)
1 Comment
Marta Salas
on 10 Mar 2014
You can not define an angle and a distance between 3 points. Do you mean by pairs of those 3 points?
Accepted Answer
Roger Stafford
on 11 Mar 2014
Edited: Roger Stafford
on 11 Mar 2014
I'll show you how to find one of the angles in the triangle P1 = [x1;y1], P2 = [x2;y2], P3 = [x3;y3]. The inner angle at vertex P1 is given by:
A1 = atan2(abs((x2-x1)*(y3-y1)-(x3-x1)*(y2-y1)), ...
(x2-x1)*(x3-x1)+(y2-y1)*(y3-y1));
As for the "distance", please tell us what kind of distance you have in mind. Distance from what to what?
2 Comments
More Answers (1)
Marta Salas
on 11 Mar 2014
The distance can be calculated as the norm of the vector between two points:
P1 = [2; 50], P2 = [9; 40], P3 = [5; 20]
d1 = norm(P2-P1);
d2 = norm(P3-P1);
distances =[d1; d2]
See Also
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!