Changeset 145 for trunk/Packages/Common/Geometric.pas
- Timestamp:
- Jun 5, 2023, 6:44:57 PM (18 months ago)
- File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/Packages/Common/Geometric.pas
r144 r145 1 unit UGeometric;1 unit Geometric; 2 2 3 3 interface … … 8 8 type 9 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; 10 21 11 22 function Distance(P1, P2: TPoint): Integer; … … 13 24 function AddPoint(const P1, P2: TPoint): TPoint; 14 25 function SubPoint(const P1, P2: TPoint): TPoint; 15 function PointToLineDistance(const P, V, W: TPoint ): Integer;26 function PointToLineDistance(const P, V, W: TPoint; out Intersect: TPoint): Integer; 16 27 function ComparePoint(P1, P2: TPoint): Boolean; 17 28 function RotatePoint(Center, P: TPoint; Angle: Double): TPoint; … … 25 36 function ShiftRect(ARect: TRect; Delta: TPoint): TRect; 26 37 38 27 39 implementation 28 40 … … 49 61 end; 50 62 51 function PointToLineDistance(const P, V, W: TPoint ): Integer;63 function PointToLineDistance(const P, V, W: TPoint; out Intersect: TPoint): Integer; 52 64 var 53 65 l2, t: Double; … … 67 79 if T < 0 then begin 68 80 Result := Distance(P, V); // Beyond the 'v' end of the segment 69 exit; 81 Intersect := V; 82 Exit; 70 83 end 71 84 else if T > 1 then begin 72 85 Result := Distance(P, W); // Beyond the 'w' end of the segment 86 Intersect := W; 73 87 Exit; 74 88 end; … … 76 90 TT.Y := Trunc(V.Y + T * (W.Y - V.Y)); 77 91 Result := Distance(P, TT); 92 Intersect := TT; 78 93 end; 79 94 … … 161 176 end; 162 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; 163 204 164 205 end. 165
Note:
See TracChangeset
for help on using the changeset viewer.