MATLAB: Euler angle from 3d points

angleeulerrotation

I want to compute Euler angle from 3d points which are in a same plane and nearly rectangle shape.
These 3d points are collected by robot arm. I want to know the correct rotation value of the plane for robot arm control.
I computed like below and I don't know how to convert three angles to Euler angles.
P1 = [-426159, 501913, 845131]P2 = [-48717.2, 499318, 847679]P3 = [-43057.3, 493773, 478609]P4 = [-422845, 495153, 475314]Z_angle = atan((P2(2) - P1(2)) / (P2(1) - P1(1))) * 180 / pi;Y_angle = atan((P2(3) - P1(3)) / (P2(1) - P1(1))) * 180 / pi;X_angle = atan((P1(3) - P4(3)) / (P1(2) - P4(2))) * 180 / pi;

% Lets take first 2 points and find Spherical coordinates.P1 = [-426159, 501913, 845131];P2 = [-48717.2, 499318, 847679];v = P1-P2;% Let's define si and theta in such a way that.v = [r*cos(si)*cos(theta), r*sin(theta), r*sin(si)*cos(theta)]r = norm(v);si = atan2(v(3),v(1));theta = atan2(v(2),sqrt(v(1).^2+v(3).^2));j = [cos(si)*cos(theta), sin(theta), sin(si)*cos(theta)];% Correspond to j vector you can also find orthonormal vector to ji = [sin(si), 0, -cos(si)];k = [cos(si)*sin(theta), -cos(theta), sin(si)*sin(theta)];% Rotation matrix;m = [i',j',k'];% You can use MATLAB inbuilt function to convert rotation matrix to Euler systemeul = rotm2eul(m);