[vtkusers] Angle between two vectors

Sean McBride sean at rogue-research.com
Mon Jan 6 13:48:52 EST 2014


On Mon, 6 Jan 2014 10:25:47 -0700, David Gobbi said:

>Are you sure that is the case?  For the acos method, if both of the vectors
>are normalized, that means two sqrts and two divisions.  Don't forget that
>sqrt and division each require around 10x as many cycles as addition or
>multiplication.  The atan2 method requires just one sqrt, by comparison.
>Overall, I wouldn't expect a significant difference. Of course, all of this
>might be moot because the transcendental op (acos or atan2) is probably
>the most expensive part of the whole computation.

Interesting discussion!

We have a little angle function as described here and it uses acos().  I've changed it to use atan2 and the results are equal (in my typical usage) to at least 1e-12.

I measured performance too.  On my Mac Pro, in debug, averaged after 1000 runs, the atan2 version is actually faster at 2.7 µs vs 3.7 µs for the acos version.  In release it's the opposite, with acos at 70 ns and atan2 at 379 ns.  I didn't look too closely; I'd say it's a wash. 

Cheers,

-- 
____________________________________________________________
Sean McBride, B. Eng                 sean at rogue-research.com
Rogue Research                        www.rogue-research.com 
Mac Software Developer              Montréal, Québec, Canada




More information about the vtkusers mailing list