create plane with 3d points

691 views Asked by At

The following code defines the normal vector and the radius of the plane in order to visualize it.My question is about d and offset. Is d the D from the plane equation Ax+By+Cz+D=0 (Because I must give a d and I don't find one with that code)? The code will help me define if a 3D point is above/down, in front/behind, left/right of a plane. Any feedback that would help me understand this is much appreciated.

**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]);
1

There are 1 answers

3
Boris Dalstein On BEST ANSWER

I don't understand exactly what this code is doing, but it does seem that d (which is used in the line fixture = p1+offset + n*d;) must be the signed distance between the origin and the plane defined by the three points. If you describe your plane by the equation Ax+By+Cz+D=0, with (A,B,C) being the normal unit vector n described in the code, then d = - D.

If this is correct, then whoever wrote this code was particularly evil to ask d from the caller, since it can be computed from the other inputs:

d = dot(n,p1);

Concerning your actual problem (The code will help me define if a 3D point is above/down, in front/behind, left/right of a plane.), simply use these two lines:

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

If h is null then q belongs to the plane, if it is positive then it is above the plane, and if it is negative then it is below. Here, "above" means that if you look at the plane from q, then the sequence p1->p2->p3->p1 is cycling counter-clockwise.