How to calculate the distance from all points in a 3d matrix to a plane in matlab?

时间:2015-05-24 21:53:39

标签: matlab matrix 3d

This question is from my last post,

But I will just focus on a particular part,

If I have a 3d matrix M, 256*256*124,and a plane defined by 3 points that intersect the 3d matrix, A,B,C, how to find the distance of all points in M to the plane defined by A,B,C

Here is the suggestion I got,

[X Y Z] = meshgrid(1:256,1:256,1:124)
A = [X(:)';Y(:)';Z(:)'];
n = cross([coor_A-coor_B],[coor_B-coor_C]); %The norm vector of the plane
d = norm(mean([coor_A,coor_B,coor_C]),2); %The distance from origin to the plane

According to Hesse normal form,

L = ((n*A)-d);    %The distance from all points in M to the plane 

But all the values in L are huge, which indicates that no points are found on the intersection plane.

Can anyone tell me what's wrong?

1 个答案:

答案 0 :(得分:1)

您错过了维基百科页面上的一行

formula1

,其中

formula2

所以添加这一行

n0 = n / norm(n);

并将最后一行更改为

L = ((n0*A)-d);