Incorrect rotation problem
Hi, i am using PlyFile to load and rotate a scene, the output position is indeed correct but the orientation of the point clouds are not.
Using this code:
import numpy as np
from plyfile import PlyData, PlyElement
def rotate_point_cloud(points, rotation_matrix):
return points.dot(rotation_matrix.T)
# Load the PLY file
input_filename = "input.ply"
output_filename = "rotated_output.ply"
plydata = PlyData.read(input_filename)
vertex_data = plydata['vertex'].data
# Extract points
points = np.vstack([vertex_data['x'], vertex_data['y'], vertex_data['z']]).T
# Define the rotation matrix for a 90 degree rotation around the y-axis (to the right)
rotation_angle = np.pi / 2 # 90 degrees
rotation_matrix = np.array([[np.cos(rotation_angle), 0, np.sin(rotation_angle)],
[0, 1, 0],
[-np.sin(rotation_angle), 0, np.cos(rotation_angle)]])
# Rotate the points
rotated_points = rotate_point_cloud(points, rotation_matrix)
# Update the vertex data with rotated points
vertex_data['x'] = rotated_points[:, 0]
vertex_data['y'] = rotated_points[:, 1]
vertex_data['z'] = rotated_points[:, 2]
# Create a new PlyElement for the rotated vertices
vertex_element = PlyElement.describe(vertex_data, 'vertex')
# Write the rotated point cloud to a new PLY file in binary little-endian format
PlyData([vertex_element], text=False, byte_order='<').write(output_filename)
print(f"Rotated point cloud saved to {output_filename}")
I get the following output:
Any idea of what could be? Thank you very much in advance.
I guess it theoretically could be a plyfile bug, but from what you wrote, I think it's more likely that the bug is somewhere else. However, if you think it really is something in plyfile, it would help me a lot if you could minimize your failing example so that I and others could reproduce it.
Closing due to lack of information. Feel free to reopen if you can confirm it's a plyfile bug or can provide enough data for me to debug this.