Changeset 49 for trunk/UGeometric.pas
- Timestamp:
- Nov 26, 2017, 12:32:16 AM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/UGeometric.pas
r44 r49 19 19 function RotatePoint(Center, P: TPoint; Angle: Double): TPoint; 20 20 function RotatePoints(Center: TPoint; P: TPointArray; Angle: Double): TPointArray; 21 function LineIntersect(LineAP1, LineAP2, LineBP1, LineBP2: TPoint): TPoint; 21 function LineIntersect(LineAP1, LineAP2, LineBP1, LineBP2: TPoint; 22 out Intersection: TPoint): Boolean; 22 23 function ArcTan2Point(Point: TPoint): Float; 23 24 function ArcTanPoint(Point: TPoint): Float; … … 100 101 end; 101 102 102 function LineIntersect(LineAP1, LineAP2, LineBP1, LineBP2: TPoint): TPoint; 103 function LineIntersect(LineAP1, LineAP2, LineBP1, LineBP2: TPoint; 104 out Intersection: TPoint): Boolean; 103 105 Var 104 106 LDetLineA, LDetLineB, LDetDivInv: Double; 105 107 LDiffLA, LDiffLB: TPoint; 108 D: Double; 106 109 begin 110 if (LineAP1 = LineAP2) or (LineBP1 = LineBP2) then begin 111 Result := False; 112 Exit; 113 end; 107 114 LDetLineA := LineAP1.X * LineAP2.Y - LineAP1.Y * LineAP2.X; 108 115 LDetLineB := LineBP1.X * LineBP2.Y - LineBP1.Y * LineBP2.X; … … 111 118 LDiffLB := SubPoint(LineBP1, LineBP2); 112 119 113 LDetDivInv := 1 / ((LDiffLA.X * LDiffLB.Y) - (LDiffLA.Y * LDiffLB.X)); 120 D := ((LDiffLA.X * LDiffLB.Y) - (LDiffLA.Y * LDiffLB.X)); 121 if D = 0 then begin 122 // Parallel lines without intersection 123 Result := False; 124 Exit; 125 end; 126 LDetDivInv := 1 / D; 114 127 115 Result.X := Trunc(((LDetLineA * LDiffLB.X) - (LDiffLA.X * LDetLineB)) * LDetDivInv); 116 Result.Y := Trunc(((LDetLineA * LDiffLB.Y) - (LDiffLA.Y * LDetLineB)) * LDetDivInv); 128 Intersection.X := Trunc(((LDetLineA * LDiffLB.X) - (LDiffLA.X * LDetLineB)) * LDetDivInv); 129 Intersection.Y := Trunc(((LDetLineA * LDiffLB.Y) - (LDiffLA.Y * LDetLineB)) * LDetDivInv); 130 Result := True; 117 131 end; 118 132
Note:
See TracChangeset
for help on using the changeset viewer.