Rigid body rotation of a set of points to align 3 on a plane

3 views (last 30 days)
Hello All I have a set of points (X,Y,Z). I want to pick 3 points which have the smallest z co-ordinate and rotate all the points I have so that these 3 points lie on the X-Y plane or a plane parallel to it.
I have defined the XYZ triplet as variable XYZ XYZ=[X Y Z];
Next I translate the points so that the lowest point is at the origin. XYZ_sort=sortrows(XYZ,3); XYZ_sort(:,1)=XYZ_sort(:,1)-XYZ_sort(1,1); XYZ_sort(:,2)=XYZ_sort(:,2)-XYZ_sort(1,2); XYZ_sort(:,3)=XYZ_sort(:,3)-XYZ_sort(1,3);
Next I find the rotation matrix to rotate these points to align them with the X-Y plane. (Found this piece of code online) w = cross(XYZ_sort(2,:)-XYZ_sort(1,:),XYZ_sort(3,:)-XYZ_sort(1,:)); w = w/norm(w); R = [null(w),w.']; if det®<0, R(:,1:2) = R(:,2:-1:1); end
Now I multiply my original set of data with this rotation matrix XYZ_R=XYZ_sort*R;
It does align the 3 points so that they are on X-Y plane but the rest of the points do not seem to be rotated by same order. Can someone tell me what I am doing wrong and if they have an alternative way of doing this.
Thanks
Aditya

Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!