# Is it possible to specify the direction of rotation in VectorAngle function?

If I use the function VectorAngle[{1,0},{1,-1}], is it possible to obtain the angle generated by rotating around the axis counter clock wise? In other words, I would move from the first vector to the second in the positive direction. My output would be (7/4)*Pi instead of Pi/4.

-
How about 2 Pi - VectorAngle[{1, 0}, {1, -1}]? – bill s Jun 20 '14 at 17:28
Is there a way to specify what direction I moved with respect to the first vector? – Kaisey Jun 20 '14 at 17:40

Not with VectorAngle alone. One way to go about this:

directedangle[a_, b_] :=
If[Sign@Det[{a, b}] >= 0, VectorAngle[a, b], 2 π - VectorAngle[a, b]]

directedangle[{1, 0}, {1, 1}]
directedangle[{1, 0}, {-1, 1}]
directedangle[{1, 0}, {1, -1}]


π/4

(3 π)/4

(7 π)/4

-
very nice, but the format of the output is not correct (confusing) :) – eldo Jun 20 '14 at 20:26
@eldo sorry my symbol toolbar is not working right now. – Yves Klett Jun 20 '14 at 20:28
@Öskå - thanks for the edit (mine was only a quick fix) – eldo Jun 20 '14 at 20:40
@Öska thx - editing from a mobile phone is a royal pain :-) – Yves Klett Jun 20 '14 at 20:41
@eldo this helps a lot :) – Öskå Jun 20 '14 at 20:42

ArcTan version:

 (If[# < 0, # + 2 Pi , #] &@(-Subtract @@ (ArcTan @@ # & /@ #))) & /@
{{{1, 0}, {1, 1}}, {{1, 0}, {-1, 1}}, {{1, 0}, {1, -1}}}


{Pi/4, (3 Pi)/4, (7 Pi)/4}

or to put in the function form of the other answer:

 directedangle[a_, b_] :=
(If[# < 0, # + 2 Pi, #] &@(-Subtract @@ (ArcTan @@ # & /@ {a, b})))

-
would it be possible to find an algorithm for the second line of your answer? – eldo Jun 20 '14 at 21:19
Would someone be able to parse this last solution for me? I think I know what the various operators do, but I can't tell how to group them. – Spencer Rugaber Jul 17 '15 at 23:36