0

I need to sort a set of vectors in circular order. The simplest approach would be to use the angle between the vectors and a fixed axis. To get the angle, one would have to normalize the vectors which includes performing an expensive square root calculation.

As I want to avoid the costs and I don't need the particular angle - just some value that gives me the same order - I was wondering if there is a way to calculate a value for each vector that does not require the vector to be normalized and yields a similar value like the angle (i.e. if angle(x) > angle(y) then f(x) > f(y)).

wondering
  • 233
  • 3
  • 13
  • I found a solution [here](http://stackoverflow.com/questions/16542042/fastest-way-to-sort-vectors-by-angle-without-actually-computing-that-angle). Maybe the way I asked is worth keeping the question? – wondering Jun 30 '14 at 18:57

1 Answers1

1

The ratio of the y component to the x component should be enough to order the vectors without normalizing them. if the y:x ratio is larger, then the angle will be steeper. That'll work at least for the 1st quadrant (0 to 90 degrees), but the general idea should be enough to get you started.

murtuza
  • 1,041
  • 7
  • 6
  • Thanks, but how would I continue with angles > 90 degrees? I don't know the maximum length of a vector, so the value in the first quadrant could be larger that the value of the second quadrant if the vectors are longer. – wondering Jun 30 '14 at 16:40
  • for angles that are not in the first quadrant (0-90 degrees), one or both of the components will be negative. so based on which component(s) is(are) negative, you can figure out which vector the quadrant is in and then apply the same idea of looking at the y:x ratio to determine the order. – murtuza Jun 30 '14 at 21:19