the angle of a straight line drawn between 2 points



Why do this by components?  Maxima lets you calculate directly with the
complex quantities:

      GiveTurn(q,r) := mod( float( carg(b-a)/(2*%pi) ), 1)

           -s

On Sun, May 27, 2012 at 2:51 PM, Adam Majewski <adammaj1 at o2.pl> wrote:

> 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
>
>
> Adam
>
>
>
> ==== 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<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);
>
>
>
>
>
> ______________________________**_________________
> Maxima mailing list
> Maxima at math.utexas.edu
> http://www.math.utexas.edu/**mailman/listinfo/maxima<http://www.math.utexas.edu/mailman/listinfo/maxima>;
>