필터 지우기
필터 지우기

calculating angle between three points

조회 수: 93 (최근 30일)
KalMandy
KalMandy 2017년 3월 21일
편집: clarammd 2023년 4월 23일
angle = atan2(abs(det([P2-P0;P1-P0])),dot(P2-P0,P1-P0));
I have seen that the angle between three points can be calculated as above where P0 = [x0,y0], P1 = [x1,y1], and P2 = [x2,y2]
can someone tell me at which point is this angle calculated? OR any other code which does the same thing is also appreciated. Thanks
  댓글 수: 2
Bjorn Gustavsson
Bjorn Gustavsson 2017년 3월 21일
Well, why not give it a try? Put down 3 points on a paper in a triangle, use them as an input to the expression and see what it gives you. After that you should be able to figure out the answer.
HTH
KalMandy
KalMandy 2017년 3월 21일
Thanks. I know that I can try that, but I wanted to see other options too.

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

답변 (2개)

Jan
Jan 2017년 3월 21일
편집: Jan 2017년 3월 21일
The shown code calculates the angle between the lines from P0 to P1 and P0 to P2.
Neither the dot nor the cross product are stable. This means that there are some inputs for both command, which reply inaccurate output:
P0 = [x0, y0];
P1 = [x1, y1];
P2 = [x2, y2];
n1 = (P2 - P0) / norm(P2 - P0); % Normalized vectors
n2 = (P1 - P0) / norm(P1 - Po);
angle1 = acos(dot(n1, n2)); % Instable at (anti-)parallel n1 and n2
angle2 = asin(norm(cropss(n1, n2)); % Instable at perpendiculare n1 and n2
angle3 = atan2(norm(cross(n1, n2)), dot(n1, n2)); % Stable
Note that Matlab's cross does not handle 2D vectors. Therefore use this for the 2D case:
angle3 = atan2(norm(det([n2; n1])), dot(n1, n2));
  댓글 수: 1
clarammd
clarammd 2023년 4월 23일
편집: clarammd 2023년 4월 23일
What does it mean the angle to be instable at (anti-)parallel n1 and n2? Also, why the vectors need to be normalized?

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


Bharath Reddy Adapa
Bharath Reddy Adapa 2017년 3월 21일
dot product dot(P2-P0,P1-P0) can give the idea. P2-P0 can be seen as vector (or displacement) starting from P0 ending at P2.
a = (P2-P0) = [x2-x0, y2-y0] = [a1,a2] = a1 + i a2, and similary a vector b for P1-P0. dot product is a.b = ab cos(theta)
You can simply use 'theta = acos(dot(P2-P0,P1-P0))'. First part of your equation using atan2 is just the sin(theta) part

카테고리

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

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by