Home   Help Search Login Register  

Author Topic: Average direction  (Read 456 times)

0 Members and 1 Guest are viewing this topic.

Unnamed

  • Guest
Average direction
« on: 31 Oct 2003, 17:57:42 »
Hi,

I'm trying to calculate the average direction of all the units in a group using GetDir. The problem is, if Getdir returns 10 degrees for one unit and 350 degress for the other, you cant just average them out as it comes up with 180 instead of 0 degrees?

Help please, my head is begining to hurt ???

Cheers

Offline Spinor

  • Members
  • *
  • I'm a llama!
    • The chain of command
Re:Average direction
« Reply #1 on: 31 Oct 2003, 18:38:13 »
Yeah, quite nasty...seems so easy at the beginning. Another strange thing occurs
if the two directions are exactly opposite to each other. In that case no average
angle can be defined properly.

I guess the basic task is not to average the angles but to determine the vectorial sum of
the direction vectors
   V1 = (cos theta1, sin theta1)
   V2 = (cos theta2, sin theta2)
(theta1 and theta2 are the getDirs of the units):
   V=V1+V2=(cos theta1+cos theta2, sin theta1+sin theta2)
and determine its angle, which corresponds to the average angle. With that approach you
have the length of the summed vector as additional information:
Suppose you have 10 units. If the summed vector has then the length 10, you know that all
units have exactly the same direction. If it is zero they walk around like crazy.

I hope there is some easier solution than this, though ???