wu_xinjun
2022-06-07 da6ff0858f4997f79f5d8cdc88b7367a5cb710b1
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
49
50
51
52
import numpy as np
from .tools import read_ply
 
 
 
def get_rotation_matrix(angle:str):
    """generate a rotation matrix from the specific angel,
        the angle is the degree that coordinate system B rotated from coordinate A
        in direction from x to y  with z is the axis.
 
    Args:
        angle (str): the angle, value in [-360,360]
 
 
    Returns:
        rotation_matrix (np.array): the rotation matrix
    """
 
    if np.abs(float(angle))>360:
        raise ValueError(f"incorrect angle value: value in [-360,360] is excepted, but {angle} is offered.")
    angle_float = np.pi * float(angle) / 180 
    rotation_matrix = np.array(
        [[np.cos(angle_float,), np.sin(angle_float), 0.],
        [-np.sin(angle_float), np.cos(angle_float), 0.],
        [0., 0., 1.]],
        dtype=np.float16
    )
    return rotation_matrix
 
def compose_ply(muti_ply_with_angle: list):
 
    ply_nums = len(muti_ply_with_angle)
    composed_ply_List = []
 
    for ply_with_angle in muti_ply_with_angle:
        angle = ply_with_angle[0]
        ply = ply_with_angle[1]
 
        if isinstance(ply,str):
            ply = read_ply(ply)
        
        rotation_matrix = get_rotation_matrix(angle)
        rotated_ply = np.matmul(rotation_matrix,ply)
        composed_ply_List.append(rotated_ply)
    
    composed_ply_array = np.array(composed_ply_List).reshape(-1,3)
    return composed_ply_array
 
 
if __name__ == "__main__":
    m = get_rotation_matrix('180')
    print(m)