OK. Been running both approaches within the c++ 'vectors.h' framework of
POV-Ray. Initial idea is both forms could be in one inbuilt function and
therefore "munction" too.
// Original macro approach:
#macro VAngle(V1, V2)
// Tor Olav's proposal for better accuracy:
#macro AngleBetweenVectors(v1, v2)
#local v1n = vnormalize(v1);
#local v2n = vnormalize(v2);
(2*atan2(vlength(v1n - v2n), vlength(v1n + v2n)))
#end // macro AngleBetweenVectors
Over millions of randomly generated vectors with component values in the
Max dot value seen: +0.99999999991558441
Min dot value seen: -0.99999999134553685
Largest difference between approaches was 0.00000000000995055 (1e-11).
The vectors for this difference were:
Angles near zero and pi (near same-direction and nearly opposing)
showing the larger differences. The 0 angle case running larger for
differences than those near pi.
The performance difference in the context of all programming framework
VAngle to AngleBetweenVectors.
127.15 -> 164.98 ---> +29.75% slower
Taking a specific measure of the overhead out of both times:
100.5 -> 138.33 ---> +37.64% slower
I have still a few other tests in mind(1), but busy for a couple days -
(1) - Different optimizations, etc.
Post a reply to this message