点云旋转
点云旋转到XOY平面
https://blog.csdn.net/crazyquhezheng/article/details/78886655
点云根据向量旋转
# 旋转
import numpy as np
import scipy.linalg as linalg
import math
#参数分别是旋转轴和旋转弧度值
def rotate_mat(axis, radian):
return linalg.expm(np.cross(np.eye(3), axis / linalg.norm(axis) * radian))
# 旋转轴
def cal_axis(v1,v2,v3=[0,0,0]):
v1 = np.asarray(v1)
v2 = np.asarray(v2)
v3 = np.asarray(v3)
axis = np.cross(v1-v3,v2-v3)
return axis/np.linalg.norm(axis)
def get_theta(v1,v2):
v1 = np.asarray(v1)
v2 = np.asarray(v2)
return np.arccos((v1@v2)/(np.linalg.norm(v1)*np.linalg.norm(v2))) #/np.pi*180
def R_by_vector(v1,v2):
v1 = np.asarray(v1)
v2 = np.asarray(v2)
theta = get_theta(v1,v2)
axis = cal_axis(v1,v2)
print('theta:',theta*180/np.pi,'\naxis:',axis)
R = rotate_mat(axis=axis, radian=theta)
return theta,axis,R
#点云旋转
pcd_points_R = np.dot(pcd_points, R.T)
备注:pcd_points形状是nx3,那么右乘R.T
参考:https://blog.csdn.net/xiangxianghehe/article/details/81626253
点云旋转原理参考:https://blog.csdn.net/weixin_42783619/article/details/116952488
点云绕xyz轴旋转
R = mesh.get_rotation_matrix_from_xyz((np.pi/2,0,np.pi/4))
mesh_r.rotate(R, center=(0,0,0))
点云旋转内旋和外旋关系
https://guyuehome.com/19226
旋转矩阵
[
x
′
y
′
z
′
]
=
R
∗
[
x
y
z
]
\left[\begin{array}{l}x^{\prime} \\ y^{\prime} \\ z^{\prime}\end{array}\right]=R *\left[\begin{array}{l}x \\ y \\ z\end{array}\right]
⎣
⎡x′y′z′⎦
⎤=R∗⎣
⎡xyz⎦
⎤
其中 R 就是三阶的旋转矩阵。仅仅考虑绕 X、 Y 或 Z 单个轴旋转 θ (右手螺旋), R 分别为
R
X
=
[
1
0
0
0
cos
θ
−
sin
θ
0
sin
θ
cos
θ
]
R
Y
=
[
cos
θ
0
sin
θ
0
1
0
−
sin
θ
0
cos
θ
]
R
Z
=
[
cos
θ
−
sin
θ
0
sin
θ
cos
θ
0
0
0
1
]
\begin{array}{l} R_{X}=\left[\begin{array}{ccc} 1 & 0 & 0 \\ 0 & \cos \theta & -\sin \theta \\ 0 & \sin \theta & \cos \theta \end{array}\right] \\ R_{Y}=\left[\begin{array}{ccc} \cos \theta & 0 & \sin \theta \\ 0 & 1 & 0 \\ -\sin \theta & 0 & \cos \theta \end{array}\right] \\ R_{Z}=\left[\begin{array}{ccc} \cos \theta & -\sin \theta & 0 \\ \sin \theta & \cos \theta & 0 \\ 0 & 0 & 1 \end{array}\right] \end{array}
RX=⎣
⎡1000cosθsinθ0−sinθcosθ⎦
⎤RY=⎣
⎡cosθ0−sinθ010sinθ0cosθ⎦
⎤RZ=⎣
⎡cosθsinθ0−sinθcosθ0001⎦
⎤
旋转向量
设旋转向量的单位向量为 r,模为 θ。三维点(或者说三维向量) p 在旋转向量 r 的作用下变换至 p′,则:
p
′
=
cos
θ
⋅
p
+
(
1
−
cos
θ
)
(
p
⋅
r
)
r
+
sin
θ
⋅
r
×
p
p^{\prime}=\cos \theta \cdot p+(1-\cos \theta)(p \cdot r) r+\sin \theta \cdot r \times p
p′=cosθ⋅p+(1−cosθ)(p⋅r)r+sinθ⋅r×p
相互转换
设旋转向量的单位向量 r=[rx ry rz]T,旋转角度为 θ,对应的旋转矩阵为 R,则 r 到 R 的转换是:
R
=
cos
θ
I
+
(
1
−
cos
θ
)
r
r
T
+
sin
θ
[
0
−
r
z
r
y
r
z
0
−
r
x
−
r
y
r
x
0
]
R=\cos \theta I+(1-\cos \theta) r r^{T}+\sin \theta\left[\begin{array}{ccc} 0 & -r_{z} & r_{y} \\ r_{z} & 0 & -r_{x} \\ -r_{y} & r_{x} & 0 \end{array}\right]
R=cosθI+(1−cosθ)rrT+sinθ⎣
⎡0rz−ry−rz0rxry−rx0⎦
⎤
其中 I 是三阶单位矩阵。反过来 R 到 r 的转换则可以利用等式:
R
−
R
T
2
=
sin
θ
[
0
−
r
z
r
y
r
z
0
−
r
x
−
r
y
r
x
0
]
\frac{R-R^{T}}{2}=\sin \theta\left[\begin{array}{ccc} 0 & -r_{z} & r_{y} \\ r_{z} & 0 & -r_{x} \\ -r_{y} & r_{x} & 0 \end{array}\right]
2R−RT=sinθ⎣
⎡0rz−ry−rz0rxry−rx0⎦
⎤
参考:https://blog.csdn.net/mightbxg/article/details/79363699