MATLAB: Angle between two planes on the X=0, Y=0 and Z=0 planes

3d plotslinear algebraMATLABplanes

Hi,
I am plotting two planes using the code mentioned here. I am using Plane fit by Adrien Leygue to find planes (best fit plane given 2 sets of points in 3D) and plot (using affine_fit.m and demo.m)
With these two planes, I want to find the angle between these two planes as seen from the YZ, XZ and XY planes.
In order to do this, I first take one plane and measure what angle it makes when it intersects the YZ, ZX and XY planes individually. (I get 3 angles Angle_XYi, Angle_YZi, Angle_ZXi ) _Basically, when my plane intersects say, the XY plane, it forms a line. I am finding the angle using: atand((y2-y1)/(x2-x1)) . This will be Angle_XYi .
Similarly for YZ and XZ planes, I obtain angles Angle_YZi, Angle_ZXi.
I do this individually for both planes, obtaining Angle_XYii, Angle_YZii, Angle_ZXii for plane2.
I simply take their differences to get the required angles:
Angle1 = Angle_XYi - Angle_XYii
Angle2 = Angle_YZi - Angle_YZii
Angle3 = Angle_ZXi - Angle_ZXii
Angle1 is my angle computed, to indicate that this is the angle between the two lines, formed by the two planes upon intersecting with the XY plane. Similarly Angle2 and Angle3 is found.
The first plane is plot using Points_plane1 and the second plane using Points_plane2.
I have attached the two sets of points Points_plane1 and Points_plane2, along with my code.
The output of my code is Angle1 = -0.1382, Angle2 = -2.1913, Angle3 = -0.0079.
When I visually inspected my plots (after plotting both the planes in a single figure), I got different angles. For example, I made Y= 0 (by simply rotating the plot in 3D such that only XZ plane is seen).
Next, I calculated the angle using atand((y2-y1)/(x2-x1)).
For the red plane, I got: atand((160-134)/(175-(-100))) = 5.4 degrees. (I reiterate, on manual visual inspection I got these points)
while for blue plane: atand((95-85)/(130-(-160))) = 1.9 degrees.
I know this is not an accurate method, but this is how I am veryfying at present, just to know if I'm heading towards the right direction. The difference should be around 3.4 degrees. This is not what I'm getting as Angle3 from the code.
Where am I going wrong? How else should I calculate the angles I want?
All the files referred to are here : https://www.dropbox.com/sh/zn1sz41z2qw7pxz/AAB0335ZLjwM73V5k2ogIA3ta?dl=0

Best Answer

Hard to answer, because it's unclear (to me) what it is you're trying to compute. Your 2 given planes, with normals N1 and N2, intersect the XY plane in 2 lines. Is it the angle between these lines that you want? If so, that angle is,
Nxy=[0 0 1]; %unit normal to XY plane
N1=N1/norm(N1); %make sure all normals are unit vectors
N2=N2/norm(N2);
Angle_XY=acosd(dot(cross(N1,Nxy), cross(N2,Nxy))); %the result
Same sort of thing for the XZ and YZ planes.