Re: trig
- Posted by "Patrick Barnes" <mistertrik at hotmail.com> Apr 19, 2004
- 629 views
A suggestion... sqrt() functions take time. Not much, but if you can eliminate them, all the better. Rather than finding the normal vector all the time, build your pre-defined angles list with vectors that have the larger component set to 1 or -1, and the other scaled accordingly. For example, 0 degrees would be [1,0], 45 degrees would be [1,1], 90 degrees would be [0,1] and 180 degrees would be [-1,0]. That way, to scale your vector down to fit the standard, divide both by the larger value. For example: [112.2,40] would become [1, 0.356...] To find which angle is closest, do a binary search on your index of values, as others have said. But this normalising method is much faster than using sqrts. MrTrick