Changeset 13351


Ignore:
Timestamp:
09/13/12 10:19:06 (13 years ago)
Author:
jschierm
Message:

NEW: Python version of SegIntersect.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk-jpl/src/m/geometry/SegIntersect.m

    r13010 r13351  
    1 function bool=SegIntersect(seg1,seg2)
     1function bval=SegIntersect(seg1,seg2)
    22%SEGINTERSECT - test of segments intersection
    33%
     
    77%
    88%   Usage:
    9 %      bool=SegIntersect(seg1,seg2)
     9%      bval=SegIntersect(seg1,seg2)
    1010
    11 bool=1;
     11bval=1;
    1212
    1313xA=seg1(1,1); yA=seg1(1,2);
     
    1616xD=seg2(2,1); yD=seg2(2,2);
    1717
    18 O2A=[xA;yA]-[xD/2+xC/2;yD/2+yC/2];
    19 O2B=[xB;yB]-[xD/2+xC/2;yD/2+yC/2];
    20 O1C=[xC;yC]-[xA/2+xB/2;yB/2+yA/2];
    21 O1D=[xD;yD]-[xA/2+xB/2;yB/2+yA/2];
     18O2A=[xA;yA]-[xD/2.+xC/2.;yD/2.+yC/2.];
     19O2B=[xB;yB]-[xD/2.+xC/2.;yD/2.+yC/2.];
     20O1C=[xC;yC]-[xA/2.+xB/2.;yB/2.+yA/2.];
     21O1D=[xD;yD]-[xA/2.+xB/2.;yB/2.+yA/2.];
    2222
    2323n1=[yA-yB;xB-xA]; %normal vector to segA
    24 n2=[yC-yD;xD-xC]; %normal vectot to segB
     24n2=[yC-yD;xD-xC]; %normal vector to segB
    2525
    2626test1=n2'*O2A;
     
    2828
    2929if test1*test2>0
    30         bool=0;
     30        bval=0;
    3131        return;
    3232end
     
    3636
    3737if test3*test4>0
    38         bool=0;
     38        bval=0;
    3939        return;
    4040end
     
    4444
    4545        %projection on the axis O1O2
    46         O2O1=[xA/2+xB/2;yB/2+yA/2]-[xD/2+xC/2;yD/2+yC/2];
     46        O2O1=[xA/2.+xB/2.;yB/2.+yA/2.]-[xD/2.+xC/2.;yD/2.+yC/2.];
    4747        O1A=O2O1'*(O2A-O2O1);
    4848        O1B=O2O1'*(O2B-O2O1);
     
    5050        O1D=O2O1'*O1D;
    5151       
    52         %test if one point is included in the other segment (->bool=1)
     52        %test if one point is included in the other segment (->bval=1)
    5353        if (O1C-O1A)*(O1D-O1A)<0
    54                 bool=1;
     54                bval=1;
    5555                return;
    5656        end
    5757        if (O1C-O1B)*(O1D-O1B)<0
    58                 bool=1;
     58                bval=1;
    5959                return;
    6060        end
    6161        if (O1A-O1C)*(O1B-O1C)<0
    62                 bool=1;
     62                bval=1;
    6363                return;
    6464        end
    6565        if (O1A-O1D)*(O1B-O1D)<0
    66                 bool=1;
     66                bval=1;
    6767                return;
    6868        end
    6969
    70          %test if the 2 segments have the same middle (->bool=1)
     70         %test if the 2 segments have the same middle (->bval=1)
    7171        if O2O1==0
    72                 bool=1;
     72                bval=1;
    7373                return;
    7474        end
    7575
    7676        %else
    77         bool=0;
     77        bval=0;
    7878        return;
    7979end
Note: See TracChangeset for help on using the changeset viewer.