Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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.

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

2 Answers 2

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

share|improve this answer
    
very nice, but the format of the output is not correct (confusing) :) –  eldo Jun 20 at 20:26
    
@eldo sorry my symbol toolbar is not working right now. –  Yves Klett Jun 20 at 20:28
    
@Öskå - thanks for the edit (mine was only a quick fix) –  eldo Jun 20 at 20:40
    
@Öska thx - editing from a mobile phone is a royal pain :-) –  Yves Klett Jun 20 at 20:41
    
@eldo this helps a lot :) –  Öskå Jun 20 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})))
share|improve this answer
    
would it be possible to find an algorithm for the second line of your answer? –  eldo Jun 20 at 21:19

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.