How to state the compass direction between two coordinates

What code can state the direction between two coordinates?
For example,
Input a,b;c,d (a,b to c,d)
a,b (x,y coordinates from place 1) to b,c (x,y coordinates to place 2)
Output: N,NE,E,SE,S,SW,W,NW or here (if it's the same place)?
Number examples:
Input: 1,1;1,2
Output = N
Input: 1,1:2,1
Output = E
Input 1,1:2,2
Output = NE
Input: 1,1:0,0
Output = SW
Input 13,13;13,13
Output = 'Here'

 採用された回答

Matt J
Matt J 2019 年 2 月 14 日
編集済み: Matt J 2019 年 2 月 14 日

0 投票

You would do
angle=atan2d(d-b,c-a);
and then, based on the numeric value of angle, assign a compass direction:

2 件のコメント

Sam Accura
Sam Accura 2019 年 2 月 14 日
編集済み: Sam Accura 2019 年 2 月 14 日
Yes that function is perfect. How though would you donate the input variables to a,b;c,d format?
i.e how would you link input 1,2;3,4 to a,b;c,d for the formula?
Sam Accura
Sam Accura 2019 年 2 月 14 日
Actually dont worry. I found this relating to the variables...
thanks for the help.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

質問済み:

2019 年 2 月 14 日

コメント済み:

2019 年 2 月 14 日

Community Treasure Hunt

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

Start Hunting!

Translated by