the angle of a straight line drawn between 2 points



On 27.05.2012 21:36, Stavros Macrakis wrote:
> 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)

Thx for an answer.
It works. I know that for experts it is obvious but for me it is hard to 
get such solution.


Adam




>
>             -s
>
> On Sun, May 27, 2012 at 2:51 PM, Adam Majewski <adammaj1 at o2.pl
> <mailto: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 <mailto:Maxima at math.utexas.edu>
>     http://www.math.utexas.edu/__mailman/listinfo/maxima
>     <http://www.math.utexas.edu/mailman/listinfo/maxima>;
>
>
>
>
> _______________________________________________
> Maxima mailing list
> Maxima at math.utexas.edu
> http://www.math.utexas.edu/mailman/listinfo/maxima