Reputation: 307
I am trying to calculate the signed angle between two vectors or angles on the circle. For example, from 330 to 30 should give 60 (clockwise as positive) and from 30 to 330 should give -60. I have tried to implement the method given in Finding Signed Angle Between Vectors . Below is the relevant code I have tried.
to-report signed-angle [a1 a2]
let v1 list sin a1 cos a1
let v2 list sin a2 cos a2
let v1x item 0 v1
let v1y item 1 v1
let v2x item 0 v2
let v2y item 0 v2
report atan (v1x * v2y - v1y * v2x) (v1x * v2x + v1y * v2y)
end
But this code does not give the correct answer even though it seems to be an approved answer for other languages. I know that NetLogo angles are 0 (up) and 90 (right). I have also tried converting the angles to conventional form using the method described in the 'atan documentation', but this also did not give correct answers. Also, I will call this reporter every tick for every link, so if any one has ideas on how this method could be streamlined, I would much appreciate it.
Upvotes: 1
Views: 840
Reputation: 9620
subtract-headings 30 330
will give you what you asked for by saying "clockwise is positive (against the example you gave).
Upvotes: 3