File Exchange

## get angle and radian between two points

version 3.0.0.0 (103 KB) by Abbas Manthiri S

### Abbas Manthiri S (view profile)

Simple code for find angle between two points

Updated 24 Mar 2017

The atan2 function is an extended version of the trigonometric inverse tangent function.
In the figure below, tan?=y/x, so tan-1y/x=?. The atan2 function just calculates tan-1y/x with y and x as separate parameters.
The reason it does so is to give a more accurate answer: since the tangent function is periodic,
there are multiple values of x and y that would appear to have the same angle (but do not).
Also, atan2 provides the correct values when y/x is undefined, such as at p/2.
%Input O-(x1,y1) and P-(x2,y2)points
%Output Angle
%devloper Er.Abbas Manthiri S
%Email-abbasmanthiribe@gmail.com

### Cite As

Abbas Manthiri S (2020). get angle and radian between two points (https://www.mathworks.com/matlabcentral/fileexchange/60148-get-angle-and-radian-between-two-points), MATLAB Central File Exchange. Retrieved .

ANKUR KUMAR

Abbas Manthiri S

@ Rob Champbell
Thanks

Rob Campbell

Excellent

Abbas Manthiri S

### Abbas Manthiri S (view profile)

@James Tursa
Thanks
I updated my coding
now check it up
IT is 100% working correctly

James Tursa

### James Tursa (view profile)

This function does not work. In particular, the author combines the output of the atan function (in radians) directly with internal variables that are clearly in degrees (e.g., 360 and 180). The boundary case results are incorrectly coded as well.

It is also not at all clear why this function is even needed, since all of the quadrant code stuff the author employs to adjust the result of his atan call could be avoided by appropriately using atan2 in the first place. E.g.,

>> pointO = [1 0];
>> pointP = [1 1];
>> getAngle(pointO,pointP)
ans =
>> atan2(norm(cross([pointO 0],[pointP 0])),dot(pointO,pointP))*180/pi
ans =

Abbas Manthiri S

### Abbas Manthiri S (view profile)

Now errors corrected

Abbas Manthiri S

### Abbas Manthiri S (view profile)

I used some simple logic with trigonometry formula...

But there need to change I shall do my best

later i will attach clear explaination

Jan

### Jan (view profile)

I do not understand the description.

Subtracting 360 from the value will not help, if it is e.g. 1e6. You need the MOD() function.