Home > atmlab > geodetic > line_plane_intersect.m

line_plane_intersect

PURPOSE ^

LINE_PLANE_INTERSECT returns the intersection point between a plane and and a line

SYNOPSIS ^

function [y,x]=line_plane_intersect(P1,P2,P3,n)

DESCRIPTION ^

LINE_PLANE_INTERSECT returns the intersection point between a plane and and a line

    FORMAT [y,x]=line_plane_intersect(P1,P2,P3,n)

    OUT        y     the intersection point in cartesian coordinate
                           if y=nan the line is parallell to the plane
                   x      a scalar which information on the intersection point
                           x=1 the intersection is at point P1
                           x=2 the intersection is at point P2
                           x=3 the intersection is between point P1 and P2
                           x=4 the intersection is not between point P1 and P2
 
    IN            P1  cartesian coordinates of a point on the line
                    P2  cartesian coordinates of a point on the line
                    P3  cartesian coordinates of a point on the plane
                    n    the normal to the plane

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

DOWNLOAD ^

line_plane_intersect.m

SOURCE CODE ^

0001 %LINE_PLANE_INTERSECT returns the intersection point between a plane and and a line
0002 %
0003 %    FORMAT [y,x]=line_plane_intersect(P1,P2,P3,n)
0004 %
0005 %    OUT        y     the intersection point in cartesian coordinate
0006 %                           if y=nan the line is parallell to the plane
0007 %                   x      a scalar which information on the intersection point
0008 %                           x=1 the intersection is at point P1
0009 %                           x=2 the intersection is at point P2
0010 %                           x=3 the intersection is between point P1 and P2
0011 %                           x=4 the intersection is not between point P1 and P2
0012 %
0013 %    IN            P1  cartesian coordinates of a point on the line
0014 %                    P2  cartesian coordinates of a point on the line
0015 %                    P3  cartesian coordinates of a point on the plane
0016 %                    n    the normal to the plane
0017 %
0018 
0019 %HISTORY: created by Bengt Rydberg 2011-11-16
0020 function [y,x]=line_plane_intersect(P1,P2,P3,n)
0021 
0022 
0023 
0024 
0025 %check input
0026 rqre_datatype( P1, @istensor1 );                        %&%
0027 rqre_datatype( P2, @istensor1 );                        %&%
0028 rqre_datatype( P3, @istensor1 );                        %&%
0029 rqre_datatype( n, @istensor1 );                        %&%
0030 if length(P1)~=3                            %&%
0031     error('P1 must have length 3')                        %&%
0032 end                                                %&%
0033 if length(P2)~=3                            %&%
0034     error('P2 must have length 3')                        %&%
0035 end                                                %&%
0036 if length(P3)~=3                            %&%
0037     error('P3 must have length 3')                        %&%
0038 end                                                %&%
0039 if length(n)~=3                                %&%
0040     error('n must have length 3')                        %&%
0041 end                                                %&%
0042 
0043 n=n';
0044 
0045 u=(n*(P3-P1))/(n*(P2-P1));
0046 
0047 if (n*(P2-P1))==0
0048     %the line is parallell to the plane
0049     y=nan;
0050     x=nan;
0051 else
0052    y=P1+u*(P2-P1);
0053    if u>0 & u<1
0054        x=3;
0055    elseif u==0
0056       x=1;
0057    elseif u==1  
0058       x=2;
0059    else
0060      x=4;
0061    end
0062 end

Generated on Mon 15-Sep-2014 13:31:28 by m2html © 2005