Vec3D.relativeAngleDeg(Vec3D) possible bug [resolved]


I’ve been playing around with the vector functions packaged in Panda and have come across an interesting thing (bug?):

>>> from pandac.PandaModules import *
>>> a = Vec3D(1,0,0)
>>> b = Vec3D(1,1,0)
>>> c = Vec3D(0,0,1)
>>> d = Vec3D(0,1,0)
>>> a.relativeAngleDeg(b)
>>> a.relativeAngleDeg(d)
>>> a.relativeAngleDeg(c)
>>> e = Vec3D(0,1,1)
>>> a.relativeAngleDeg(e)
>>> f = Vec3D(1,0,1)
>>> a.relativeAngleDeg(f)

The error is in a.relativeAngleDeg©: this should give an output of 90, as the x and z axis are orthogonal; instead it gives an output of 0. Also the last line, a.relativeDeg(f) should give an output of 45.

Does this function only work in the x/y plane? It appears to…

The reason I am interested is that a built in C++ function that quickly gives the signed (right handed) angle would be of tremendous use; using angleDeg and having to both normalize and then add the sign back in is perfectly possible, but I’m guessing would be slower.

Any advise on the subject is also most welcome!

Learning Panda,

Hmm, weird. This works though:

>>> Vec3.angleDeg(Vec3(1, 0, 0), Vec3(0, 0, 1))
>>> Vec3.relativeAngleDeg(Vec3(1, 0, 0), Vec3(0, 0, 1))

It seems that relativeAngleDeg only supports 2d:

relative_angle_rad(const FLOATNAME(LVector3) &other) const {
  return atan2((_v.v._0*other._v.v._1)-(_v.v._1*other._v.v._0), dot(other));


Kind of a dumb question, but where can I find the C++ code for these functions? I’d love to be able to look up the workings of these functions myself (so that I won’t be bugging you guys so much). I’ve been looking a bit and can’t find them. I’m currently working on a windows machine.


In this case it’s in an inline header file and can be found in C:\Panda3D-1.5.4\include\lvector3_src.I.
If it’s not, grab the source version, and it will be in panda3d\panda\src\linmath\lvector3_src.I.

I don’t know if this particular thing is really a bug. You’d have to ask David for that.

I would agree that its not a bug, after seeing the code; the documentation is just a bit misleading.

Thanks for the help!