# [Maxima] the angle of a straight line drawn between 2 points

Sun May 27 13:51:36 CDT 2012

```Hi,

I need a function which computes the angle of a straight line drawn
between 2 points.
It should give result in turns ( from 0 to 1 ).
I have made a function :

GiveTurn

and some tests for it.

It gives expected results. Can I as for an opinion of experts ?

TIA

==== code ==========================

kill(all);

/*
Determines the angle of a straight line drawn between point one and two.
The number returned, which is a double in degrees, tells us how much
we have to rotate a horizontal line clockwise for it to match the line
between the two points.

http://codeforeverything.wikidot.com/get-angle-of-line-between-two-points

*/

GiveTurn(z3,z4):=(dx:realpart(z4)-realpart(z3),
dy:imagpart(z4)-imagpart(z3),
b:atan2(dy,dx),
if (b<0) then b:b+2*%pi else b,
float(b/(2*%pi)));

compile(all)\$

GiveTurn(0, 1+0*%i);
GiveTurn(0, 1+1*%i);
GiveTurn(0, 0+1*%i);
GiveTurn(0,-1+1*%i);
GiveTurn(0,-1+0*%i);
GiveTurn(0,-1-1*%i);
GiveTurn(0, 0-1*%i);
GiveTurn(0, 1-1*%i);

```