How can I calculate the angle between two surfaces?

조회 수: 11 (최근 30일)
Tobias Reichold
Tobias Reichold 2017년 5월 18일
댓글: Tobias Reichold 2017년 6월 3일
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!

채택된 답변

Roger Stafford
Roger Stafford 2017년 5월 19일
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));
  댓글 수: 1
Tobias Reichold
Tobias Reichold 2017년 6월 3일
Thank you very much for your time and help! This has helped a lot!

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

David Goodmanson
David Goodmanson 2017년 5월 18일
편집: David Goodmanson 2017년 5월 18일
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
Tobias Reichold
Tobias Reichold 2017년 5월 18일
Here is my code so far:
p00 = 4.234e-05;
p10 = 5.574e-07;
p01 = -7.654e-08;
for x = 1:50
for y = 1:50
f(x,y) = p00 + p10*x + p01*y;
y = y + 1;
if y > 50
x = x+1;
end
end
end
figure
surfnorm(f)
hold on
zero_plane = zeros(50,50);
surfnorm(zero_plane)
hold on
f is the tilted plane in a 50x50 matrix. zero_plane is the 50x50 reference plane against which I want to find the tilt angle. When I run the surfnorm I get the normal vectos displayed as shown in the graph:
But I'm not sure how to get the data from the red vectors and turn them into the angle.
I want to get an angle for each vector pair from the reference and the tilted plane, so I will end up with 50x50 angles (2500 seperate values).
David Goodmanson
David Goodmanson 2017년 5월 18일
편집: David Goodmanson 2017년 5월 18일
I see what you mean, see the edited answer above with details added.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by