Skip to content

rotate_rig

rotate_rig(P, R)

Rotates a rig by a rotation matrix R

Parameters:

Name Type Description Default
P (b, 3, 4) float numpy array

World transformation of each bone

required
R (3, 3) float numpy array

Rotation matrix

required

Returns:

Name Type Description
Prot (b, 3, 4) float numpy array

Rotated world transformation of each bone

Source code in src\fast_cody\rotate_rig.py
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
def rotate_rig(P, R):
    """
    Rotates a rig by a rotation matrix R

    Parameters
    ----------
    P : (b, 3, 4) float numpy array
        World transformation of each bone
    R : (3, 3) float numpy array
        Rotation matrix

    Returns
    -------
    Prot : (b, 3, 4) float numpy array
        Rotated world transformation of each bone

    """
    k = P.shape[0]
    if (len(P.shape) == 3):
        k = P.shape[0]
        Prot = np.zeros(P.shape)
        for b in range(k):
            # stack a row of [0 0 0 1] tp T0
            # same with T
            T = P[b, :, :]
            Trot = R @ T
            Prot[b, :, :] = Trot[:3, :]

    if (len(P.shape) == 4 ):
        frames = P.shape[0]
        k = P.shape[1]
        Prot = np.zeros(P.shape)
        for frame in range(frames):
            for b in range(k):
                # stack a row of [0 0 0 1] tp T0
                T = P[frame, b, :, :]
                Trot = R @ T
                Prot[frame, b, :, :] = Trot[:3, :]

    return Prot