Reputation: 843
I have a set of points (X,Y,Z vertices) that I can read from STL file in MATLAB. They are the points that make up a cube.
I want to know the angle by which this cube might be rotated with X/Y/Z axis.
Can anyone please give any leads how this can be done?
Thanks
Upvotes: 1
Views: 959
Reputation: 5821
First you need to assign a coordinate system to the cube. You can do this by picking a point on the cube and drawing an axis on each of the three edges that are connected to it (these would be in the directions to the three closest points). There is more than one way a cube can be put in line with the XYZ axes, so the choice of point is arbitrary. You could find the closest point to the origin or just pick one at random.
So now you have your XYZ coordinate system (given by three column vectors that form a matrix A
) and your cube coordinate system (given by matrix C
). If you want the matrix transformation T
that connects to the two you can solve the matrix equation C = T*A
. Since A
is just the identity matrix, we have T = C
. If you want the actual angles you can align the axes one-bye-one with rotation matrices using a same matrix inversion process repeatedly.
Upvotes: 1
Reputation: 3633
To find out how the cube rotate against the X/Y/Z axis, you should construct the local coordinate system for the cube first, which can be easily done in the following steps, assuming you know all the 8 corner points of the cube and how they are connected to each other to form the cube.
1) Pick any point out of the 8 points, denote this as P0.
2) There should be 3 other points that are connected to P0. Denote these 3 points as P1, P2 and P3.
3) Create vectors from P0 to P1, P2 and P3 and unitize these 3 vectors. These 3 unit vectors, denoted as v1, v2 and v3, should be orthogonal to each other and can be used as a local coordinate system for the cube. You can assign v1, v2 and v3 as the x, y and z axes for the local coordinate system but you need to make sure that they follow the right-hand rule.
4) Now, you have the local coordinate system, you can easily compute the angles with respect to the original coordinate system.
Upvotes: 1