Vector angle incorrect

from direct.showbase.ShowBase import ShowBase
from panda3d.core import Vec3, Point3

class MyApp(ShowBase):
    def __init__(self):
        ShowBase.__init__(self)

        up = Vec3(0, 0, 1)

        calc = Point3(0, 0, 0) - Point3(0, 0, 0)
        calc.normalize()

        print(calc.angle_deg(up))

app = MyApp()
app.run()

out:

60.000003814697266

Shouldn’t the angle be 90? Or how can I get around it, in other cases it works correctly. Of course, I can add a check for the zero value of the vector and not make calculations. It would be nice if warnings about this behavior were noted somewhere in the manual.

I would imagine that the result of normalising a zero-vector is undefined, and thus arbitrary.

To check this, what values does the normalised version of “calc” have?

This is the problem that theoretically it can be zero. I think I will change the approach of getting a vector.

1 Like

Thinking of the manual, I’ve just checked there, and it seems that “normalize” returns a boolean that is “False” if the vector was of zero-length. That might potentially provide a check for you!

1 Like