旋转矩阵变换后点云变形问题(使用单位向量仍畸变)
点云旋转非90度倍数角度出现畸变问题
尝试绕某一轴按指定角度旋转点云以保证形状无畸变,但旋转非90度倍数的角度时,点云出现变形。已确保使用单位向量作为旋转轴,但畸变问题仍存在。
代码实现
import numpy as np import math import matplotlib.pyplot as plt def rotation_matrix(axis, radian): ax, ay, az = axis[0], axis[1], axis[2] s = math.sin(radian) c = math.cos(radian) u = 1 - c return ( ( ax*ax*u + c, ax*ay*u - az*s, ax*az*u + ay*s ), ( ay*ax*u + az*s, ay*ay*u + c, ay*az*u - ax*s ), ( az*ax*u - ay*s, az*ay*u + ax*s, az*az*u + c ) ) def get_ax(): fig = plt.figure() ax = fig.add_subplot(111, projection='3d') ax.set_xlabel('X') ax.set_ylabel('Y') ax.set_zlabel('Z') ax.set_ylim3d(-5, 5) ax.set_xlim3d(-5, 5) ax.set_zlim3d(-5, 5) return ax # torus parameters major_radius = 1.5 minor_radius = 2.9 density = 15 theta = np.linspace(0, 2 * np.pi, density) phi = np.linspace(0, 2*np.pi, density) Theta, Phi = np.meshgrid(theta, phi) # parametric equations for the torus x = (major_radius + minor_radius * np.cos(Theta)) * np.cos(Phi) y = (major_radius + minor_radius * np.cos(Theta)) * np.sin(Phi) z = minor_radius * np.sin(Theta) # coordinate array original_points = np.array([x.flatten(), y.flatten(), z.flatten()]) angles = np.array([0, 45, 90]) for angle in angles: # get R matrix for unit vec axis and angle R = rotation_matrix([0,1,0], np.radians(angle)) # rotate points by R and plot rotated_points = np.dot(R, original_points) rotated_x = rotated_points[0] rotated_y = rotated_points[1] rotated_z = rotated_points[2] ax = get_ax() ax.scatter(rotated_x, rotated_y, rotated_z, color='black') plt.show()
畸变效果
旋转45度时的效果如下,该形状本应对称,倾斜视角更容易观察到畸变:

内容的提问来源于stack exchange,提问作者satindressedup4
相关产品推荐
相关产品推荐

