Reputation: 623
I'm trying to find a point in the plane closest to a given point. I have the equation of the plane, the point and the distance between them. How do I find the point in the plane which is closest to the given point?
I have a tetrahedron with sides: bcx=0, acy=0, abz=0, x/a+y/b+z/c=1 (a,b,c are not to mix with Ax+By+Cz=D in the planes equation, they are to be entered when running the script).
function [d n]=tetradist(x,y,z,a,b,c)
if z>0 && y>0 && x>0 && z<c && y<b && x<a && x/a+y/b+z/c<1
d1=abs(a*b*z)/sqrt((a*b)^2);
d2=abs(b*c*x)/sqrt((b*c)^2);
d3=abs(a*c*y)/sqrt((a*c)^2);
d4=abs(b*c*x+a*c*y+a*b*z-a*b*c)/sqrt((b*c)^2 + (a*c)^2 + (a*b)^2);
A = [d1 d2 d3 d4];
B = sort(A,'ascend');
d = B(1);
point=[x y z];
if d==d1
normalv=[0 0 a*b]';
elseif d==d2
normalv=[b*c 0 0]';
elseif d==d3
normalv=[0 a*c 0]';
else
normalv=[b*c a*c a*b]';
end
end
So now I have the shortest distance, my point as a vector and the normal vector of the closest plane. Now how do I find the point in said plane which is closest to my point 'point'?
Thanks in advance!
Upvotes: 3
Views: 4265
Reputation: 47402
If the equation of your plane is Ax + By + Cz = D and the location of the point is (P, Q, R) then the location in the plane that is closest to the point is
(P,Q,R) + λ * (A,B,C)
where
λ = (D - P*A - B*Q - C*R) / (A^2 + B^2 + C^2)
The following Matlab code calculates this point
function x = closestpoint(n, d, p)
# n is the vector [A,B,C] that defines the plane
# d is the distance of the plane from the origin
# p is the point [P,Q,R]
v = (d - sum(p.*n)) / sum(n.*n);
x = p + v * n;
Upvotes: 5