Changeset 13351
- Timestamp:
- 09/13/12 10:19:06 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk-jpl/src/m/geometry/SegIntersect.m
r13010 r13351 1 function b ool=SegIntersect(seg1,seg2)1 function bval=SegIntersect(seg1,seg2) 2 2 %SEGINTERSECT - test of segments intersection 3 3 % … … 7 7 % 8 8 % Usage: 9 % b ool=SegIntersect(seg1,seg2)9 % bval=SegIntersect(seg1,seg2) 10 10 11 b ool=1;11 bval=1; 12 12 13 13 xA=seg1(1,1); yA=seg1(1,2); … … 16 16 xD=seg2(2,1); yD=seg2(2,2); 17 17 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];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.]; 22 22 23 23 n1=[yA-yB;xB-xA]; %normal vector to segA 24 n2=[yC-yD;xD-xC]; %normal vecto tto segB24 n2=[yC-yD;xD-xC]; %normal vector to segB 25 25 26 26 test1=n2'*O2A; … … 28 28 29 29 if test1*test2>0 30 b ool=0;30 bval=0; 31 31 return; 32 32 end … … 36 36 37 37 if test3*test4>0 38 b ool=0;38 bval=0; 39 39 return; 40 40 end … … 44 44 45 45 %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.]; 47 47 O1A=O2O1'*(O2A-O2O1); 48 48 O1B=O2O1'*(O2B-O2O1); … … 50 50 O1D=O2O1'*O1D; 51 51 52 %test if one point is included in the other segment (->b ool=1)52 %test if one point is included in the other segment (->bval=1) 53 53 if (O1C-O1A)*(O1D-O1A)<0 54 b ool=1;54 bval=1; 55 55 return; 56 56 end 57 57 if (O1C-O1B)*(O1D-O1B)<0 58 b ool=1;58 bval=1; 59 59 return; 60 60 end 61 61 if (O1A-O1C)*(O1B-O1C)<0 62 b ool=1;62 bval=1; 63 63 return; 64 64 end 65 65 if (O1A-O1D)*(O1B-O1D)<0 66 b ool=1;66 bval=1; 67 67 return; 68 68 end 69 69 70 %test if the 2 segments have the same middle (->b ool=1)70 %test if the 2 segments have the same middle (->bval=1) 71 71 if O2O1==0 72 b ool=1;72 bval=1; 73 73 return; 74 74 end 75 75 76 76 %else 77 b ool=0;77 bval=0; 78 78 return; 79 79 end
Note:
See TracChangeset
for help on using the changeset viewer.