Cutting point line and plane
조회 수: 6 (최근 30일)
이전 댓글 표시
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
채택된 답변
harsha001
2019년 3월 20일
편집: harsha001
2019년 3월 21일
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
harsha001
2019년 3월 21일
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.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!