[Bf-python] BPython bug AngleBetweenVecs
Jonathan Merritt
j.merritt at pgrad.unimelb.edu.au
Tue Mar 29 06:39:17 CEST 2005
Campbell Barton wrote:
> Hi, this has caused me grief in the past and I have been using a
> python version of AngleBetweenVecs.
>
> Just now I found the problem. when AngleBetweenVecs compares 2 vectors
> that are the same, it can return nan, nan being a float type.
> nothing is equal to nan except float('nan').
> Shold be changed to return 0 instead of nan?\
I just took a quick look, and I'd say this method needs a bit of a
re-write. In addition to the bug you mention, it also has the
additional (undocumented bug/feature) side-effect of normalizing any
vectors that are passed to it.
if you try:
v1 = Mathutils.Vector(1,2,3)
v2 = Mathutils.Vector(1,2,3)
print Mathutils.AngleBetweenVecs(v1,v2)
you get a small number (close to zero), as expected.
if you then try:
v1 = Mathutils.Vector(1,2,3)
print Mathutils.AngleBetweenVecs(v1,v1)
you get nan.
Within the function, the vectors should be copied *first* before they
are normalized (so that you don't have any side-effects). It will then
work better (giving you the first result and not a NAN). Can't write a
patch just now, but can do it next weekend if nobody gets there before me.
--
Jonathan Merritt BE(Mech)/BSc
PhD Student - Equine Biomechanics
The University of Melbourne
Veterinary Clinical Centre, Werribee
More information about the Bf-python
mailing list