#2 quat.toAngleAxis() returns axis==vec3(0,0,0) for angle == 0

Marcel Teun

I use cgkit-2.0.0alpha2:

I have e.g. a quaternion q = quat(0, vec3(1, 0, 0))
I want to reused the axis of this quaternion with a new
angle, e.g:
q2 = quat( newAngle, q.toAngleAxis()[1])
However I get:
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "cgtypes.pyx", line 4464, in cgtypes.quat.__new__
File "cgtypes.pyx", line 4880, in
ValueError: axis mustn't be the null vector.

Actually I have to feeling that this is a bug, the axis
is still vec3(1,0,0) that is not changed by the fact
that the angle == 0.

/Marcel Teun


  • Matthias Baas

    Matthias Baas - 2005-02-20

    Logged In: YES

    Well, the problem is that the "axis" part of the quaternion is
    sin(angle/2)*axis. This results in zero if you pass an angle of 0
    which means the axis information is lost and cannot be
    restored later. So if you need the original axis you have to
    store that axis somewhere else in addition to the quat.

    But your code highlighted another problem. The result of
    toAngleAxis() can't be passed into fromAngleAxis() if the
    original angle was 0. This shouldn't be and I've changed that in
    cvs. Now fromAngleAxis() also accepts the null vector as axis
    (which is the same as passing an angle of 0).

    By the way, you were still using cgkit1. The error message is
    referring to "cgtypes.pyx" which is the cgtypes implementation
    of cgkit1. For cgkit2 Pyrex isn't used anymore. However, the
    above would also have happened with cgkit2.
    Everything from cgkit2 is beneath the "cgkit" package, so you
    have to import cgkit.cgtypes instead of just cgtypes to get
    the new module. It is intentional that both packages can be
    installed at the same time as long as cgkit2 isn't final and you
    might want to fall back to cgkit1 in some situations.

    - Matthias -

  • Matthias Baas

    Matthias Baas - 2005-02-20
    • status: open --> closed

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks