0

下面的代码定义了平面的法线向量和半径以便可视化它。我的问题是关于d和偏移。是d平面方程中的 D吗Ax+By+Cz+D=0(因为我必须给出 ad而我找不到带有该代码的 D)?该代码将帮助我定义 3D 点是否位于平面的上方/下方、前方/后方、左侧/右侧。非常感谢任何有助于我理解这一点的反馈。

**function [fixture,n,min_radius] = planePointPoint(p1,p2,p3,q,d,varargin)**

% p1, p2 and p3 -3d points that define an oriented plane.
%q is the point that is tested against this plane
% p1+offset is the fixture point for the plane.
% d is the offset distance for the plane in the direction of n.
% optional argument offset is a 3-vector denoting an offset to be added to the fixture point during min_radius calculation
%
% function returns sequence of fixture points and unit normals along with 
% minimum radii that make sense to visualize position of q in relation to the plane.
offset = [0;0;0];
if (nargin>6)
    offset = varargin{1};
end
n = cross(p1 - p3,p2 - p3);%defines normal vector
n = n./repmat(sqrt(sum(n.^2)),3,1);%normalise  normal vector
offset = repmat(offset,1,mot.nframes) -   repmat(dot(n,repmat(offset,1,mot.nframes)),3,1).*n;
%points = p1 + n*d;
fixture = p1+offset  + n*d;
dist_q = dot(n,q-fixture);
dist_p1 = dot(n,p1-fixture);
dist_p2 = dot(n,p2-fixture);
dist_p3 = dot(n,p3-fixture);
q_proj = q - repmat(dist_q,3,1).*n;
p1_proj = p1 - repmat(dist_p1,3,1).*n;
p2_proj = p2 - repmat(dist_p2,3,1).*n;
p3_proj = p3 - repmat(dist_p3,3,1).*n;
radius_q = sqrt(sum((fixture-q_proj).^2));
radius_p1 = sqrt(sum((fixture-p1_proj).^2));
radius_p2 = sqrt(sum((fixture-p2_proj).^2));
radius_p3 = sqrt(sum((fixture-p3_proj).^2));
min_radius = max([radius_q; radius_p1; radius_p2; radius_p3]);
4

1 回答 1

0

我不明白这段代码在做什么,但似乎d(在 line 中使用fixture = p1+offset + n*d;)必须是原点和由三个点定义的平面之间的有符号距离。如果您通过方程式 描述您的平面Ax+By+Cz+D=0,其中(A,B,C)是代码中描述的法线单位向量n,那么d = - D

如果这是正确的,那么编写此代码的人向d调用者询问特别邪恶,因为它可以从其他输入中计算出来:

d = dot(n,p1);

关于您的实际问题 ( The code will help me define if a 3D point is above/down, in front/behind, left/right of a plane.),只需使用以下两行:

n = cross(p1 - p3,p2 - p3);
h = dot(n,q-p1);

如果h为空则q属于平面,如果为正则在平面上方,如果为负则在平面下方。在这里,“上方”意味着如果你从 看平面q,那么序列p1-> p2-> p3->p1是逆时针循环的。

于 2013-09-04T03:53:58.810 回答