Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Intersection of a plane and finite line segment in 3D space

Subject: Intersection of a plane and finite line segment in 3D space

From: Liana

Date: 4 Apr, 2011 00:23:04

Message: 1 of 10

Hi,

Below is a code that I'm using to find intersection point of a plane and line in 3D space. Now I need to determine if the intersection occurs between a finite line segment [P4 P5]. How could I check it?
Thanks.
        % Get the coordinates of points P1, P2 and P3 that represent the plane
        P1 = [10 10 10];
        P2 = [10 20 10;
        P3 = [20 10 10];
        % Define normal of the plane
        normal = cross(P1-P2, P1-P3);
        syms x y z
        P = [x,y,z];
        % Find an equation for the plane through the points P1, P2 and P3
        planefunction = dot(normal, P-P1);
        % Represent the line
        P4 = [5 5 5];
        P5 = [3 1.5 1.5];
        % Parametrise the line
        syms t
        line = P4 + t*(P5-P4);
        % Find the intersection point if any exists
        newfunction = subs(planefunction, P, line);
        t0 = solve(newfunction);
        point = subs(line, t, t0);
        ans = subs(planefunction, P, point);

Subject: Intersection of a plane and finite line segment in 3D space

From: Roger Stafford

Date: 4 Apr, 2011 00:35:05

Message: 2 of 10

"Liana" wrote in message <inb318$kcs$1@fred.mathworks.com>...
> Hi,
>
> Below is a code that I'm using to find intersection point of a plane and line in 3D space. Now I need to determine if the intersection occurs between a finite line segment [P4 P5]. How could I check it?
> Thanks.
> % Get the coordinates of points P1, P2 and P3 that represent the plane
> P1 = [10 10 10];
> P2 = [10 20 10;
> P3 = [20 10 10];
> % Define normal of the plane
> normal = cross(P1-P2, P1-P3);
> syms x y z
> P = [x,y,z];
> % Find an equation for the plane through the points P1, P2 and P3
> planefunction = dot(normal, P-P1);
> % Represent the line
> P4 = [5 5 5];
> P5 = [3 1.5 1.5];
> % Parametrise the line
> syms t
> line = P4 + t*(P5-P4);
> % Find the intersection point if any exists
> newfunction = subs(planefunction, P, line);
> t0 = solve(newfunction);
> point = subs(line, t, t0);
> ans = subs(planefunction, P, point);
- - - - - - - - -
  The plane will intersect the line segment whenever its endpoints lie on opposite sides of the plane. That is when dot(normal,P4-P1) and dot(normal,P5-P1) have opposite signs.

Roger Stafford

Subject: Intersection of a plane and finite line segment in 3D space

From: Liana

Date: 4 Apr, 2011 00:59:05

Message: 3 of 10

Thanks, Roger. Let me just clarify one more thing: in my case P1 is a point [10 10 10]. so, is it enough just to check if dot(normal,P4-P1) and dot(normal,P5-P1) have opposite sign?

"Roger Stafford" wrote in message <inb3np$1bs$1@fred.mathworks.com>...
> "Liana" wrote in message <inb318$kcs$1@fred.mathworks.com>...
> > Hi,
> >
> > Below is a code that I'm using to find intersection point of a plane and line in 3D space. Now I need to determine if the intersection occurs between a finite line segment [P4 P5]. How could I check it?
> > Thanks.
> > % Get the coordinates of points P1, P2 and P3 that represent the plane
> > P1 = [10 10 10];
> > P2 = [10 20 10;
> > P3 = [20 10 10];
> > % Define normal of the plane
> > normal = cross(P1-P2, P1-P3);
> > syms x y z
> > P = [x,y,z];
> > % Find an equation for the plane through the points P1, P2 and P3
> > planefunction = dot(normal, P-P1);
> > % Represent the line
> > P4 = [5 5 5];
> > P5 = [3 1.5 1.5];
> > % Parametrise the line
> > syms t
> > line = P4 + t*(P5-P4);
> > % Find the intersection point if any exists
> > newfunction = subs(planefunction, P, line);
> > t0 = solve(newfunction);
> > point = subs(line, t, t0);
> > ans = subs(planefunction, P, point);
> - - - - - - - - -
> The plane will intersect the line segment whenever its endpoints lie on opposite sides of the plane. That is when dot(normal,P4-P1) and dot(normal,P5-P1) have opposite signs.
>
> Roger Stafford

Subject: Intersection of a plane and finite line segment in 3D space

From: Roger Stafford

Date: 4 Apr, 2011 01:23:04

Message: 4 of 10

"Liana" wrote in message <inb54p$lpc$1@fred.mathworks.com>...
> Thanks, Roger. Let me just clarify one more thing: in my case P1 is a point [10 10 10]. so, is it enough just to check if dot(normal,P4-P1) and dot(normal,P5-P1) have opposite sign?
- - - - - - - - -
  Yes, it is sufficient. The respective values of dot(normal,P4-P1) and dot(normal,P5-P1) are unchanged if you replace P1 with P2 or P3, because all three points lie in the plane.

Roger Stafford

Subject: Intersection of a plane and finite line segment in 3D space

From: Liana

Date: 4 Apr, 2011 02:21:04

Message: 5 of 10

I suppose that I missed one thing: P1 = [10 10 10] Do these numbers correspond to x,y and z coordinates of the same point or do they correspond to 'x' coordinates of three points? As far as I understand the second variant is correct. (?)

% Plane
P1 = [10 10 10]; P2 = [20 10 10]; P3 = [10 10 20];
% Line segment
P4 = [5 5 5]; P5 = [13.75 12.5 2.5];


"Roger Stafford" wrote in message <inb6ho$d0e$1@fred.mathworks.com>...
> "Liana" wrote in message <inb54p$lpc$1@fred.mathworks.com>...
> > Thanks, Roger. Let me just clarify one more thing: in my case P1 is a point [10 10 10]. so, is it enough just to check if dot(normal,P4-P1) and dot(normal,P5-P1) have opposite sign?
> - - - - - - - - -
> Yes, it is sufficient. The respective values of dot(normal,P4-P1) and dot(normal,P5-P1) are unchanged if you replace P1 with P2 or P3, because all three points lie in the plane.
>
> Roger Stafford

Subject: Intersection of a plane and finite line segment in 3D space

From: Liana

Date: 4 Apr, 2011 02:28:04

Message: 6 of 10

The thing is that if I assume that P1, P2 and P3 are points with x,y,z coordinates, then sometimes I get incorrect results:
% Plane in 3D space
P1 = [10 10 10]; P2 = [20 10 10]; P3 = [10 10 20];
% Line segment in 3D space
P4 = [5 5 5]; P5 = [13.75 12.5 2.5];
normal = cross(P1-P2, P1-P3);
d1 = dot(normal,P4-P1)
d2 = dot(normal,P5-P1)

Answer:
d1=500; d2 =-250

It means that the line intersects the plane, however it doesn't. Where is my error?

"Roger Stafford" wrote in message <inb6ho$d0e$1@fred.mathworks.com>...
> "Liana" wrote in message <inb54p$lpc$1@fred.mathworks.com>...
> > Thanks, Roger. Let me just clarify one more thing: in my case P1 is a point [10 10 10]. so, is it enough just to check if dot(normal,P4-P1) and dot(normal,P5-P1) have opposite sign?
> - - - - - - - - -
> Yes, it is sufficient. The respective values of dot(normal,P4-P1) and dot(normal,P5-P1) are unchanged if you replace P1 with P2 or P3, because all three points lie in the plane.
>
> Roger Stafford

Subject: Intersection of a plane and finite line segment in 3D space

From: Liana

Date: 4 Apr, 2011 06:54:04

Message: 7 of 10

I'm sorry, I should paraphrase my question. What I'm searching is the intersection of the line segment and the triangle (not tetrahedron) in 3D space. I think that's the reason why I get incorrect results. In fact, the triangle belongs to the plane, but it is just a fragment of that plane. Does anybody know how to update my code to determine such intersection? Thanks a lot for any suggestion.

"Liana" wrote in message <inbabk$amd$1@fred.mathworks.com>...
> The thing is that if I assume that P1, P2 and P3 are points with x,y,z coordinates, then sometimes I get incorrect results:
> % Plane in 3D space
> P1 = [10 10 10]; P2 = [20 10 10]; P3 = [10 10 20];
> % Line segment in 3D space
> P4 = [5 5 5]; P5 = [13.75 12.5 2.5];
> normal = cross(P1-P2, P1-P3);
> d1 = dot(normal,P4-P1)
> d2 = dot(normal,P5-P1)
>
> Answer:
> d1=500; d2 =-250
>
> It means that the line intersects the plane, however it doesn't. Where is my error?
>
> "Roger Stafford" wrote in message <inb6ho$d0e$1@fred.mathworks.com>...
> > "Liana" wrote in message <inb54p$lpc$1@fred.mathworks.com>...
> > > Thanks, Roger. Let me just clarify one more thing: in my case P1 is a point [10 10 10]. so, is it enough just to check if dot(normal,P4-P1) and dot(normal,P5-P1) have opposite sign?
> > - - - - - - - - -
> > Yes, it is sufficient. The respective values of dot(normal,P4-P1) and dot(normal,P5-P1) are unchanged if you replace P1 with P2 or P3, because all three points lie in the plane.
> >
> > Roger Stafford

Subject: Intersection of a plane and finite line segment in 3D space

From: Rune Allnor

Date: 4 Apr, 2011 07:51:20

Message: 8 of 10

On Apr 4, 8:54 am, "Liana " <liananapalk...@email.arizona.edu> wrote:
> I'm sorry, I should paraphrase my question. What I'm searching is the intersection of the line segment and the triangle (not tetrahedron) in 3D space. I think that's the reason why I get incorrect results. In fact, the triangle belongs to the plane, but it is just a fragment of that plane.

1) Find the intersection point p between the line L and
   the plane P, if such a point exists
2) Determine if p belongs to the finite section of L
3) Determine if p is located in the interior of the
   triangle T, given by the points (q,r,s).

Rune

Subject: Intersection of a plane and finite line segment in 3D space

From: Liana

Date: 4 Apr, 2011 08:16:04

Message: 9 of 10

Thanks, Rune. Another solution could be the following: 1) check if the ray intersects the triangle, and 2) in case of intersection, check if the intersection point belongs to the line segment defined by two points in 3D.
 
Rune Allnor <allnor@tele.ntnu.no> wrote in message <70a9d01e-e1bb-47da-83f6-5dc20ab2d44a@dr5g2000vbb.googlegroups.com>...
> On Apr 4, 8:54 am, "Liana " <liananapalk...@email.arizona.edu> wrote:
> > I'm sorry, I should paraphrase my question. What I'm searching is the intersection of the line segment and the triangle (not tetrahedron) in 3D space. I think that's the reason why I get incorrect results. In fact, the triangle belongs to the plane, but it is just a fragment of that plane.
>
> 1) Find the intersection point p between the line L and
> the plane P, if such a point exists
> 2) Determine if p belongs to the finite section of L
> 3) Determine if p is located in the interior of the
> triangle T, given by the points (q,r,s).
>
> Rune

Subject: Intersection of a plane and finite line segment in 3D space

From: Rune Allnor

Date: 4 Apr, 2011 08:29:26

Message: 10 of 10

On Apr 4, 10:16 am, "Liana " <liananapalk...@email.arizona.edu> wrote:
> Thanks, Rune. Another solution could be the following: 1) check if the ray intersects the triangle, and 2) in case of intersection, check if the intersection point belongs to the line segment defined by two points in 3D.

Well - not really.

The procedure I stated does the least amount of computations
necessary before each check. If you are a little bit careful
about how you state the problem, my method wastes only a small
number of computations in case p is outside the relevant interval
of L. If it is, there is no point in doing all the computations
required to determine if p is inside T.

With your suggestion one would need to do all the computations
every time. Might be a lot slower, depending on the application.

Rune

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us