How can I calculate the angle between two surfaces?
    10 views (last 30 days)
  
       Show older comments
    
    Tobias Reichold
 on 18 May 2017
  
    
    
    
    
    Commented: Tobias Reichold
 on 3 Jun 2017
            I have two planes with 50x50 points and I want to find the angle between them. The first is a reference plane at z = 0 and the second is a measured surface sample (see graph). I can get matlab to display the surface normal using surfnorm but it doesn't seem to output that data anywhere.
Any help would be very appreciated!

0 Comments
Accepted Answer
  Roger Stafford
      
      
 on 19 May 2017
        The command
[Nx,Ny,Nz] = surfnorm(Z)
will return surface normals to surface Z. See:
https://www.mathworks.com/help/matlab/ref/surfnorm.html
However these normals will change from point to point. You need the equation of the best fit plane to obtain a single over-all normal to your points. For a plane with equation
a*x+b*y+c*z+d = 0
its normal is the vector v = [a,b,c]. To make it of unit length do:
v = v/norm(v);
As I think you are aware, the angle between the normals to two planes is the same as the angle between those planes. The angle between two 3D vectors v1 and v2 is:
   ang = atan2(norm(cross(v1,v2)),dot(v1,v2));
More Answers (1)
  David Goodmanson
      
      
 on 18 May 2017
        
      Edited: David Goodmanson
      
      
 on 18 May 2017
  
      Hi Tobias, You get the components of the unit normals with [nx ny nz] = surfnorm(x,y,z) so if you have two surfaces z1 and z2, then
[nx1 ny1 nz1] = surfnorm(x,y,z1);   % each is 50 x 50 in your case
[nx2 ny2 nz2] = surfnorm(x,y,z2);
n1dotn2 = nx1.*nx2 + ny1.*ny2 + nz1.*nz2;
theta = acos(n1dotn2)             % 50 x 50, in radians
In your case the lower surface is the xy plane with n2 = (0,0,1) so you could just use theta = acos(nz1)
2 Comments
  David Goodmanson
      
      
 on 18 May 2017
				
      Edited: David Goodmanson
      
      
 on 18 May 2017
  
			I see what you mean, see the edited answer above with details added.
See Also
Categories
				Find more on Surface and Mesh Plots in Help Center and File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!