Changeset 315 for trunk/Packages/Common/Geometric.pas
- Timestamp:
- Jun 19, 2024, 11:15:44 PM (5 months ago)
- File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/Packages/Common/Geometric.pas
r314 r315 1 unit UGeometric; 2 3 {$mode delphi} 1 unit Geometric; 4 2 5 3 interface … … 10 8 type 11 9 TPointArray = array of TPoint; 10 11 { TVector } 12 13 TVector = record 14 Position: TPoint; 15 Direction: TPoint; 16 function GetLength: Double; 17 function GetAngle: Double; 18 procedure SetLength(Value: Double); 19 class function Create(P1, P2: TPoint): TVector; static; 20 end; 12 21 13 22 function Distance(P1, P2: TPoint): Integer; … … 15 24 function AddPoint(const P1, P2: TPoint): TPoint; 16 25 function SubPoint(const P1, P2: TPoint): TPoint; 17 function PointToLineDistance(const P, V, W: TPoint ): Integer;26 function PointToLineDistance(const P, V, W: TPoint; out Intersect: TPoint): Integer; 18 27 function ComparePoint(P1, P2: TPoint): Boolean; 19 28 function RotatePoint(Center, P: TPoint; Angle: Double): TPoint; … … 27 36 function ShiftRect(ARect: TRect; Delta: TPoint): TRect; 28 37 38 29 39 implementation 30 40 … … 51 61 end; 52 62 53 function PointToLineDistance(const P, V, W: TPoint ): Integer;63 function PointToLineDistance(const P, V, W: TPoint; out Intersect: TPoint): Integer; 54 64 var 55 65 l2, t: Double; … … 69 79 if T < 0 then begin 70 80 Result := Distance(P, V); // Beyond the 'v' end of the segment 71 exit; 81 Intersect := V; 82 Exit; 72 83 end 73 84 else if T > 1 then begin 74 85 Result := Distance(P, W); // Beyond the 'w' end of the segment 86 Intersect := W; 75 87 Exit; 76 88 end; … … 78 90 TT.Y := Trunc(V.Y + T * (W.Y - V.Y)); 79 91 Result := Distance(P, TT); 92 Intersect := TT; 80 93 end; 81 94 … … 163 176 end; 164 177 178 { TVector } 179 180 function TVector.GetLength: Double; 181 begin 182 Result := Sqrt(Sqr(Direction.X) + Sqr(Direction.Y)); 183 end; 184 185 function TVector.GetAngle: Double; 186 begin 187 Result := ArcTan2(Direction.Y, Direction.X); 188 end; 189 190 procedure TVector.SetLength(Value: Double); 191 var 192 Angle: Double; 193 begin 194 Angle := GetAngle; 195 Direction := Point(Round(Cos(Angle) * Value), 196 Round(Sin(Angle) * Value)); 197 end; 198 199 class function TVector.Create(P1, P2: TPoint): TVector; 200 begin 201 Result.Position := P1; 202 Result.Direction := Point(P2.X - P1.X, P2.Y - P1.Y); 203 end; 165 204 166 205 end. 167
Note:
See TracChangeset
for help on using the changeset viewer.