Skip to content

Fix as_rotvec about zero #5

@bpousett

Description

@bpousett

Currently, running the following returns a vector of nans:

import spatial_casadi as sc
sc.Rotation.from_quat([0, 0, 0, 1]).as_rotvec()

It should return a zero vector. The issue is in line 423:

scale = theta / casadi.sin(theta * 0.5)

The limit as theta -> 0 of this expression is 2. But this returns nan.

Consider the implementation from scipy spatial, where they use a Taylor expansion to get around this:

        angle = 2 * atan2(_norm3(quat_single), quat_single[3])

        if angle <= 1e-3:  # small angle Taylor series expansion
            angle2 = angle * angle
            scale = 2 + angle2 / 12 + 7 * angle2 * angle2 / 2880
        else:  # large angle
            scale = angle / sin(angle / 2)

Perhaps something similar with ca.if_else would do the trick.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions