Reputation: 1735
I have a plain with known four co-ordinates and a line with two known co-ordinates as shown in figure.
The four co-ordinates of plane are
A = (-5 -5 -8)
B = ( 15 15 -8)
C = ( 15 15 12)
D = ( -5 -5 12)
The co-ordinates of line are
M = (1.3978,40,6.1149)
N = 4.3943, 4.8078,0.3551)
In this case line and plain intersects,then how can I find point of intersection of line and plane in 3D space by using MATLAB? or How can I check both are intersecting or not?
I have tried to find solution by following video tutorial to find equation of plane from three points and tutorial for finding point where line intersects a plain
But in my case, equation of plane is zero. So I am confused. Can anyone help me?
Thanks in advance, Manu
Upvotes: 1
Views: 4362
Reputation: 3873
I would use simple linear algebra to find the intersection point.
Let n
be normal to the plain (you can calculate it as a vector product of say N = cross(AB, AD)
, then unit n = N / |N|
where |N| = sqrt(dot(N, N))
is length of vector N.
You can use the following function from matlabcentral which covers all the corner cases as well (such as when the line is parallel to the plane) and describes them in the comments.
Example from comment:
A =[ -6.8756 39.9090 10.0000],B =[ -6.0096 40.4090 10.0000],C =[ -6.0096 40.4090 11.0000],D=[ -6.8756 39.9090 11.0000];
P0 =[ 1.3978 40.0000 6.1149],P1 =[ 4.3943 -4.8078 0.3551];
I don't know where you made a mistake, but I am pretty sure there is an intersection point which is outside your segment. So you should have got check=3
. Here is the output of step by step operation:
>> AB = B-A
AB = 0.8660 0.5000 0
>> AD = D-A
AD = 0 0 1
>> n = cross(AB,AD)/sqrt(dot(cross(AB,AD),cross(AB,AD)))
n = 0.5000 -0.8660 0
>> [I,check]=plane_line_intersect(n,A,P0,P1)
I = 1.0961 44.5116 6.6948
check = 3
It produces the same results with any other point (B, C or D) passed in. check=3
means there is an intersection point I, which is outside of the P01 segment.
As a verification step, notice that normal n has Nz = 0
which means that it's perpendicular to the Z axis. The only way a line wouldn't intersect with it is if it would be parallel to Z axis (and therefore vector P01 would be parallel to Z and have zero Z component).
Your P01 is not aligned with Z:
>> P01 = P1 - P0
P01 = 2.9965 -44.8078 -5.7598
Upvotes: 2