“Average” of multiple quaternions?

前端 未结 13 1655
执念已碎
执念已碎 2020-12-12 17:31

I\'m trying to make the switch from matrices to quaternions for skeletal animation in my OpenGL program, but I\'ve encountered a problem:

Given a number of unit quat

13条回答
  •  独厮守ぢ
    2020-12-12 17:56

    This is my implementation in python of Tolga Birdal's algorithm:

    import numpy as np
    
    def quatWAvgMarkley(Q, weights):
        '''
        Averaging Quaternions.
    
        Arguments:
            Q(ndarray): an Mx4 ndarray of quaternions.
            weights(list): an M elements list, a weight for each quaternion.
        '''
    
        # Form the symmetric accumulator matrix
        A = np.zeros((4, 4))
        M = Q.shape[0]
        wSum = 0
    
        for i in range(M):
            q = Q[i, :]
            w_i = weights[i]
            A += w_i * (np.outer(q, q)) # rank 1 update
            wSum += w_i
    
        # scale
        A /= wSum
    
        # Get the eigenvector corresponding to largest eigen value
        return np.linalg.eigh(A)[1][:, -1]
    

提交回复
热议问题