Cutting point line and plane
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
ibabinaca
el 20 de Mzo. de 2019
Comentada: harsha001
el 21 de Mzo. de 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.
0 comentarios
Respuesta aceptada
harsha001
el 20 de Mzo. de 2019
Editada: harsha001
el 21 de Mzo. de 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 comentarios
harsha001
el 21 de Mzo. de 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.
Más respuestas (0)
Ver también
Categorías
Más información sobre Surface and Mesh Plots en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!