Angle between two best-fit planes
6 views (last 30 days)
Show older comments
I have a set of points (as in Points3D.mat attached here). I find the equation of best fit plane using affine_fit by Adrien Leygue. This is how I call the function:
[ n_1,V_1,p_1,X_1,Y_1,Z_1 ] = Fit_Display_Plane( point3d );
[ n_2,V_2,p_2,X_2,Y_2,Z_2 ] = Fit_Display_Plane( point3d );
Function definition:
function [ n,V,p,x,y,z ] = Fit_Display_Plane( point3d )
[n,V,p] = affine_fit(point3d);
[S1,S2] = meshgrid([100 -50 200]); %([10000 -5000 20000]);
%generate the point coordinates
x = p(1)+[S1(:) S2(:)]*V(1,:)';
y = p(2)+[S1(:) S2(:)]*V(2,:)';
z = p(3)+[S1(:) S2(:)]*V(3,:)';
%plot the plane
surf(reshape(x,3,3),reshape(y,3,3),reshape(z,3,3),'facecolor','blue','facealpha',0.5);
% xlabel('x');
% ylabel('y');
% zlabel('z');
% axis equal
end
When I do this, I obviously get the same set of values for [ n_1,V_1,p_1,X_1,Y_1,Z_1 ] and [ n_2,V_2,p_2,X_2,Y_2,Z_2 ]
My main intention is to find the angle between two planes ( the first plane is the reference plane. The second plane's tilt w.r.t first plane in X, Y and Z axes should be found .),
To do so, I am doing:
function [ Angle1,Angle2,Angle3 ] = FindAlphaBeta( n_1,p_1,n_2,p_2)
N1 = n_1;
N2 = n_2;
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
Nxz=[0 1 0]; %unit normal to XY plane
Angle_XZ=acosd(dot(cross(N1,Nxz), cross(N2,Nxz))) %the result
Nyz=[1 0 0]; %unit normal to XY plane
Angle_YZ=acosd(dot(cross(N1,Nyz), cross(N2,Nyz))) %the result
Angle1 = Angle_XY;
Angle2 = Angle_XZ;
Angle3 = Angle_YZ;
end
Since in the current case, n_1 = n_2 and p_1 = p_2, I am supposed to get zero value for Angle1, Angle2 and Angle3. (i.e. the angle between the lines formed when these two planes are intersected by X = 0 plane, Y = 0 plane and Z = 0 plane)
Instead, I get these values:
Angle_XY = 88.1821; % Angle between the two lines formed when Z = 0 plane intersects
Angle_XZ = 2.5280; % Angle between the two lines formed when Y = 0 plane intersects
Angle_YZ = 14.2455; % Angle between the two lines formed when X = 0 plane intersects
Where am I going wrong?
I can see only two possibilities:
- My function FindAlphaBeta is wrong.
- function affine_fit is not giving me the results what I intend to get.
Could anyone correct me? I have been trying this since a very long time. Let me know if more details are required. I need help in the linear algebra part.
Regards,
Meghana.
2 Comments
Matt J
on 29 Apr 2015
Edited: Matt J
on 29 Apr 2015
To make things easier, could you simply give us the values of n_1 and n_2 that are being generated by Fit_Display_Plane? The angle calculations done in FindAlphaBeta do not use anything else. In other words, there is no apparent reason to be feeding p_1 and p_2 to that function.
As a side note, it is not clear how to interpret the p,V,x,y,z output arguments from Fit_Display_Plane. Whoever gave you that routine, they were not kind enough to provide help text...
Answers (1)
Matt J
on 29 Apr 2015
Edited: Matt J
on 29 Apr 2015
My guess is that the fitted planes are nearly parallel to the XY plane, so that the Angle_XY result is meaningless. However, see also comments above.
At the very least, you need to modify FindAlphaBeta so that it tries to detect and handle these degenerate situations.
See Also
Categories
Find more on Calculus in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!