Changeset 63 for trunk/Packages/Common/UGeometric.pas
- Timestamp:
- Jan 5, 2023, 11:03:33 PM (23 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Packages/Common/UGeometric.pas
r54 r63 9 9 TPointArray = array of TPoint; 10 10 11 { TVector } 12 13 TVector = record 14 Position: TPoint; 15 Direction: TPoint; 16 function GetLength: Integer; 17 function GetAngle: Double; 18 end; 19 11 20 function Distance(P1, P2: TPoint): Integer; 12 21 function Dot(const P1, P2: TPoint): Double; 13 22 function AddPoint(const P1, P2: TPoint): TPoint; 14 23 function SubPoint(const P1, P2: TPoint): TPoint; 15 function PointToLineDistance(const P, V, W: TPoint ): Integer;24 function PointToLineDistance(const P, V, W: TPoint; out Intersect: TPoint): Integer; 16 25 function ComparePoint(P1, P2: TPoint): Boolean; 17 26 function RotatePoint(Center, P: TPoint; Angle: Double): TPoint; … … 50 59 end; 51 60 52 function PointToLineDistance(const P, V, W: TPoint ): Integer;61 function PointToLineDistance(const P, V, W: TPoint; out Intersect: TPoint): Integer; 53 62 var 54 63 l2, t: Double; … … 68 77 if T < 0 then begin 69 78 Result := Distance(P, V); // Beyond the 'v' end of the segment 70 exit; 79 Intersect := V; 80 Exit; 71 81 end 72 82 else if T > 1 then begin 73 83 Result := Distance(P, W); // Beyond the 'w' end of the segment 84 Intersect := W; 74 85 Exit; 75 86 end; … … 77 88 TT.Y := Trunc(V.Y + T * (W.Y - V.Y)); 78 89 Result := Distance(P, TT); 90 Intersect := TT; 79 91 end; 80 92 … … 162 174 end; 163 175 176 { TVector } 177 178 function TVector.GetLength: Integer; 179 begin 180 Result := Trunc(Sqrt(Sqr(Direction.X) + Sqr(Direction.Y))); 181 end; 182 183 function TVector.GetAngle: Double; 184 begin 185 Result := ArcTan2(Direction.Y, Direction.X); 186 end; 164 187 165 188 end.
Note:
See TracChangeset
for help on using the changeset viewer.