I have STL file where I want to apply 4x4 matrix.
The matrix I want to apply is:
[[2.7282, 0, 0, 0], [0, 4.0014, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]
Here is my STL file:
https://we.tl/t-v6SHprAeUZ[
^]
I have used Python code to apply matrix to the mesh (STL file) but the code didn't help me. It gives me runtime error:
Traceback (most recent call last):
File "E:\STL\matrix.py", line 17, in <module>
transformed_point = np.dot(matrix, homogeneous_point) # Apply the transformation
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: shapes (4,4) and (10,1) not aligned: 4 (dim 1) != 10 (dim 0)
What I have tried:
The code:
import numpy as np
from stl import mesh
matrix = np.array([[2.7282, 0, 0, 0],
[0, 4.0014, 0, 0],
[0, 0, 1, 0],
[0, 0, 0, 1]])
your_mesh = mesh.Mesh.from_file('E:\\STL\\Mesh4.stl')
transformed_vertices = []
for vertex in your_mesh.vectors:
homogeneous_point = np.append(vertex, 1)[:, np.newaxis]
transformed_point = np.dot(matrix, homogeneous_point)
transformed_vertices.append(transformed_point[:3, 0])
new_mesh = mesh.Mesh(np.array(transformed_vertices), remove_empty_areas=False)
new_mesh.save('E:\\STL\\output_mesh.stl')
print("Transformation applied and saved successfully.")