Changeset 25 for trunk/UGeometric.pas


Ignore:
Timestamp:
Apr 12, 2015, 12:08:05 AM (9 years ago)
Author:
chronos
Message:
  • Added: Draw track lines which go in same position side by side to see them all and be able to grab one of them. This is not yet perfectly implemented as this require to implement track points link properties first.
  • Fixed: Do not allow connect end station to grabbed track between two stations.
  • Fixed: Index on wrong list in shape distance calculation function.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/UGeometric.pas

    r13 r25  
    1313function Distance(P1, P2: TPoint): Integer;
    1414function Dot(const P1, P2: TPoint): Double;
     15function AddPoint(const P1, P2: TPoint): TPoint;
    1516function SubPoint(const P1, P2: TPoint): TPoint;
    1617function PointToLineDistance(const P, V, W: TPoint): Integer;
     
    1819function RotatePoint(Center, P: TPoint; Angle: Double): TPoint;
    1920function RotatePoints(Center: TPoint; P: TPointArray; Angle: Double): TPointArray;
     21function LineIntersect(LineAP1, LineAP2, LineBP1, LineBP2: TPoint): TPoint;
     22function ArcTan2Point(Point: TPoint): Float;
     23function ArcTanPoint(Point: TPoint): Float;
    2024
    2125implementation
     
    2933begin
    3034  Result := P1.X * P2.X + P1.Y * P2.Y;
     35end;
     36
     37function AddPoint(const P1, P2: TPoint): TPoint;
     38begin
     39  Result.X := P1.X + P2.X;
     40  Result.Y := P1.Y + P2.Y;
    3141end;
    3242
     
    8898end;
    8999
     100function LineIntersect(LineAP1, LineAP2, LineBP1, LineBP2: TPoint): TPoint;
     101Var
     102  LDetLineA, LDetLineB, LDetDivInv: Double;
     103  LDiffLA, LDiffLB: TPoint;
     104begin
     105  LDetLineA := LineAP1.X * LineAP2.Y - LineAP1.Y * LineAP2.X;
     106  LDetLineB := LineBP1.X * LineBP2.Y - LineBP1.Y * LineBP2.X;
     107
     108  LDiffLA := SubPoint(LineAP1, LineAP2);
     109  LDiffLB := SubPoint(LineBP1, LineBP2);
     110
     111  LDetDivInv := 1 / ((LDiffLA.X * LDiffLB.Y) - (LDiffLA.Y * LDiffLB.X));
     112
     113  Result.X := Trunc(((LDetLineA * LDiffLB.X) - (LDiffLA.X * LDetLineB)) * LDetDivInv);
     114  Result.Y := Trunc(((LDetLineA * LDiffLB.Y) - (LDiffLA.Y * LDetLineB)) * LDetDivInv);
     115end;
     116
     117function ArcTan2Point(Point: TPoint): Float;
     118begin
     119  Result := ArcTan2(Point.Y, Point.X);
     120end;
     121
     122function ArcTanPoint(Point: TPoint): Float;
     123begin
     124  Result := ArcTan(Point.Y / Point.X);
     125end;
    90126
    91127end.
Note: See TracChangeset for help on using the changeset viewer.