get vector orientation from coordinates of two ends

7 次查看(过去 30 天)
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