File size: 1,244 Bytes
ef5e4fa
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
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
43
44
45
46
47
48
import numpy as np


def degrees_to_radians(degrees):
    return degrees * np.pi / 180

def compute_rotation_list(params):
    x, y, z, yaw, pitch = params
    
    yaw_rad = degrees_to_radians(yaw)
    pitch_rad = degrees_to_radians(pitch)
    
    R_y = np.array([[np.cos(yaw_rad), 0, np.sin(yaw_rad)],
                    [0, 1, 0],
                    [-np.sin(yaw_rad), 0, np.cos(yaw_rad)]])
    
    R_z = np.array([[np.cos(pitch_rad), -np.sin(pitch_rad), 0],
                    [np.sin(pitch_rad), np.cos(pitch_rad), 0],
                    [0, 0, 1]])
    
    R = np.dot(R_z, R_y)
    
    rotation_list = [x, y, z] + R.flatten().tolist()
    
    return rotation_list

def convert_rt_to_relative(rt_list_all, ref_rt):
    def parse_rt(rt):
        t = np.array(rt[:3]).reshape((3, 1))
        R = np.array(rt[3:]).reshape((3, 3))
        return R, t

    R_ref, T_ref = parse_rt(ref_rt)
    R_ref_inv = R_ref.T
    T_ref_inv = -R_ref_inv @ T_ref

    new_rt_list = []

    for rt in rt_list_all:
        R_i, T_i = parse_rt(rt)

        R_new = R_ref_inv @ R_i
        T_new = R_ref_inv @ T_i + T_ref_inv

        rt_new = T_new.flatten().tolist() + R_new.flatten().tolist()
        new_rt_list.append(rt_new)

    return new_rt_list