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)
|