필터 지우기
필터 지우기

get vector orientation from coordinates of two ends

조회 수: 7 (최근 30일)
Yinan Xuan
Yinan Xuan 2018년 8월 25일
댓글: Ohad Givaty 2020년 12월 8일
I a starting point of a vector at (x1,y1) and it ends at (x2, y2).
Is there anyway I can get the vector orientation theta in rad? when theta = 0 is completely arbitrary. However, maybe it is easier when the vector is pointing to right, since sin(theta) = 0 at that point.
If use the slope approach, cases where vector is pointing straight up or down cannot be solved because the slope is inf or -inf.
Any suggestions? Thanks very much!

채택된 답변

dpb
dpb 2018년 8월 25일
편집: dpb 2018년 8월 25일
doc atan2
theta=atan2(x2-x1,y2-y1);
If you'll write x,y as vectors as
x=[x(1) x(2)]; y=[y(1) y(2)];
then you can write
theta=atan2(diff(x),diff(y));
  댓글 수: 1
Ohad Givaty
Ohad Givaty 2020년 12월 8일
you should do atan2(diff(y),diff(x));
see documentation: https://www.mathworks.com/help/matlab/ref/atan2.html

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by