Changeset 562 for Common/UGeometric.pas
- Timestamp:
- May 27, 2023, 11:00:20 AM (18 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Common/UGeometric.pas
r558 r562 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; … … 50 61 end; 51 62 52 function PointToLineDistance(const P, V, W: TPoint ): Integer;63 function PointToLineDistance(const P, V, W: TPoint; out Intersect: TPoint): Integer; 53 64 var 54 65 l2, t: Double; … … 68 79 if T < 0 then begin 69 80 Result := Distance(P, V); // Beyond the 'v' end of the segment 70 exit; 81 Intersect := V; 82 Exit; 71 83 end 72 84 else if T > 1 then begin 73 85 Result := Distance(P, W); // Beyond the 'w' end of the segment 86 Intersect := W; 74 87 Exit; 75 88 end; … … 77 90 TT.Y := Trunc(V.Y + T * (W.Y - V.Y)); 78 91 Result := Distance(P, TT); 92 Intersect := TT; 79 93 end; 80 94 … … 162 176 end; 163 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; 164 204 165 205 end. 166
Note:
See TracChangeset
for help on using the changeset viewer.