Cutting point line and plane

7 Ansichten (letzte 30 Tage)
ibabinaca
ibabinaca am 20 Mär. 2019
Kommentiert: harsha001 am 21 Mär. 2019
Hello,
I have a plane described by a normal vector n = (a,b,c) and a point P = (x,y,z). Also I have a line passing through the points Q = (x1,y1,z1) and R =(x2,y2,z2). I want to know the point where the line cuts the plane (it will always cut). Thank you.

Akzeptierte Antwort

harsha001
harsha001 am 20 Mär. 2019
Bearbeitet: harsha001 am 21 Mär. 2019
This would be an easy implementation of a direct geometric solution.
1) First you need the line in a parametric form by calculating L0 and u:
say L(t) = L0 + t*u, where t is any real scalar
u is the line direction vector given by (R-Q). So, u = (x2-x1, y2-y1, z2-z1)
and L0 is Q = (x1, y1, z1).
Thus any point on the line can be generate by using some real value of t. In particular, here, L(0) gives you point Q, and L(1) gives you point R.
2) Check if line is parallel to plane (either never intersecting or completely lying in plane) i.e. if the plane normal vector n and line vector are perpendicular
if dot(n, u) == 0, that is the case
If the line is on the plane, then check if point Q (or R) is on the plane i.e it satisfies:
dot(n, Q-P) = 0 %the line between any two points on the plane is perpendicular to the normal vector.
Otherwise, the line never intersects the plane.
3) If the line is not parallel, then it intersects the plane at one point, which can be solved for:
t_int = dot(n, P - Q) / dot (n, R - Q )
and the point is simply L(t) = L0 + t_int* u
Here's some sample code you can use to define a function:
% define:
n = [1, 1, 1];
P = [2, 3, 0];
Q = [2, .51, 1];
R = [4, 1, 1];
% calculate L0 and U for line:
L0 = Q;
u = R- Q;
%check if parallel
if dot(n,u)==0
%line parallel to plane
if dot( n, Q-P)==0
disp('Line lies in plane')
else
disp('Line never intersects plane')
end
else
%find point of intersection
t = dot(n, P - Q)/dot(n, u);
POI = L0 + t*u;
fprintf('Point of intersection is [%f %f %f]', POI(1), POI(2), POI(3) )
end
  2 Kommentare
ibabinaca
ibabinaca am 21 Mär. 2019
Bearbeitet: ibabinaca am 21 Mär. 2019
Hello,
I have tried your code, and after ploting the plane (with the normal vector and point) the line (with P and Q) and the point of intersection, i have noticed that the point doesnt match with the graphical intersection of the line and the point.
I,ve used this code for ploting:
% Plot the POI
scatter3(POI(1),POI(2),POI(3),'filled')
hold on
% Plot line PQ
plot3([Q(1) R(1)],[Q(2) R(2)],[Q(3) R(3)])
% Plot plane
w = null(n);
[Ps,Qs] = meshgrid(-50:50);
X = P(1)+w(1,1)*Ps+w(1,2)*Qs;
Y = P(2)+w(2,1)*Ps+w(2,2)*Qs;
Z = P(3)+w(3,1)*Ps+w(3,2)*Qs;
surf(X,Y,Z)
So, I think that the minus sing when calculating t isnt needed:
t = dot(n, P - Q)/dot(n, u);
harsha001
harsha001 am 21 Mär. 2019
You are right, I didn't need the minus as I used Q as origin to calculate both line directions. I have edited my answer.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by