transform x,y coordinate to angle

조회 수: 41 (최근 30일)
Rose
Rose 2020년 3월 12일
편집: Jon 2020년 3월 12일
Hi Guys,
I'm struggeling with this problem in which I have two points (x and y coordinates known) that move independent of eachother. I need to find the angle between these two points wrt North. The angle can be between -180:180. As indicated in the Figure I added, I would like to find the "red angle", but by using the sin,cos,tan equations I can only get the "blue angle".
Anyone that knows how to tackle this problem? It needs to work for all respective locations of both points to one another...
I tried the following code, but that does only result in the blue angle as expected...
heading_s=atand((y_ip-y_s)/(x_ip-x_s));

채택된 답변

Jon
Jon 2020년 3월 12일
편집: Jon 2020년 3월 12일
I would think that you could use atan2 or atan2d (if you want result in degrees) for this.
For example
x1 = [2;1] % first point
x2 = [-1;-1] % second point
delta = x2 - x1 % vector that points from x1 to x2
heading = atan2d(delta(2),delta(1))
which results in
heading =
-146.3099
  댓글 수: 2
Jon
Jon 2020년 3월 12일
edited above,originally I had arguments in reverse order
Jon
Jon 2020년 3월 12일
편집: Jon 2020년 3월 12일
If you want the heading to give conventional compass reading (N = 0, E = 90, S = 180, W = 270 you can use
heading = atan2d(delta(2),delta(1))
compassHeading = mod(90-heading,360)

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Cartesian Coordinate System Conversion에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by