フィルターのクリア

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 Center および File ExchangePlasma Physics についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by