POV-Ray : Newsgroups : povray.general : Proposed VAngle alternative AngleBetweenVectors. (Attn: Tor Olav) : Proposed VAngle alternative AngleBetweenVectors. (Attn: Tor Olav) Server Time
18 May 2022 01:37:16 EDT (-0400)
  Proposed VAngle alternative AngleBetweenVectors. (Attn: Tor Olav)  
From: William F Pokorny
Date: 11 May 2021 04:50:49
Message: <609a4569$1@news.povray.org>
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 
+-25.0 range.

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 - 
starting now.

(1) - Different optimizations, etc.

Bill P.

Post a reply to this message

Copyright 2003-2021 Persistence of Vision Raytracer Pty. Ltd.