以下代码定义法线向量和平面半径以便可视化。我的问题是关于d
和偏移量。 d
是平面方程Ax+By+Cz+D=0
中的D(因为我必须给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]);
答案 0 :(得分:0)
我不明白这段代码到底在做什么,但似乎d
(在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
- > {{1逆时针循环。