四元数几个操作

1. 向量v绕一轴旋转一角度(用四元数表示q)

v’ = q*v*q’

2.四元数分解到另一轴上

/**
    Assume that the current quaternion represents the relative orientation between two coordinate frames A and B.
    This method decomposes the current relative rotation into a twist of frame B around the axis v passed in as a
    parameter, and another more arbitrary rotation.

    AqB = AqT * TqB, where T is a frame that is obtained by rotating frame B around the axis v by the angle
    that is returned by this function.

    In the T coordinate frame, v is the same as in B, and AqT is a rotation that aligns v from A to that
    from T.

    It is assumed that vB is a unit vector!! This method returns TqB, which represents a twist about
    the axis vB.
*/
Quaternion Quaternion::decomposeRotation(const Vector3d vB) const{
    //we need to compute v in A's coordinates
    Vector3d vA = this->rotate(vB);
    vA.toUnit();

    double temp = 0;

    //compute the rotation that alligns the vector v in the two coordinate frames (A and T)
    Vector3d rotAxis = vA.crossProductWith(vB);
    rotAxis.toUnit();
    double rotAngle = -safeACOS(vA.dotProductWith(vB));

    Quaternion TqA = Quaternion::getRotationQuaternion(rotAngle, rotAxis*(-1));
    return TqA * (*this);
}

转载于:https://www.cnblogs.com/justin_s/archive/2011/01/06/1927798.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值