Changeset 13 for trunk/UGeometric.pas


Ignore:
Timestamp:
Mar 27, 2015, 12:49:17 PM (9 years ago)
Author:
chronos
Message:
  • Added: Rotate train and their passengers according track.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/UGeometric.pas

    r4 r13  
    88  Classes, SysUtils, Math;
    99
     10type
     11  TPointArray = array of TPoint;
     12
    1013function Distance(P1, P2: TPoint): Integer;
    1114function Dot(const P1, P2: TPoint): Double;
     
    1316function PointToLineDistance(const P, V, W: TPoint): Integer;
    1417function ComparePoint(P1, P2: TPoint): Boolean;
     18function RotatePoint(Center, P: TPoint; Angle: Double): TPoint;
     19function RotatePoints(Center: TPoint; P: TPointArray; Angle: Double): TPointArray;
    1520
    1621implementation
     
    6772end;
    6873
     74function RotatePoint(Center, P: TPoint; Angle: Double): TPoint;
     75begin
     76  P := Point(P.X - Center.X, P.Y - Center.Y);
     77  Result := Point(Center.X + Round(P.X * Cos(Angle) - P.Y * Sin(Angle)),
     78    Center.Y + Round(P.X * Sin(Angle) + P.Y * Cos(Angle)));
     79end;
     80
     81function RotatePoints(Center: TPoint; P: TPointArray; Angle: Double): TPointArray;
     82var
     83  I: Integer;
     84begin
     85  SetLength(Result, Length(P));
     86  for I := 0 to High(P) do
     87    Result[I] := RotatePoint(Center, P[I], Angle);
     88end;
     89
    6990
    7091end.
Note: See TracChangeset for help on using the changeset viewer.