ShortenPath

function ShortenPath(const path: TPathD; pathEnd: TPathEnd; amount: double): TPathD;


Shortens an open path at one or both ends depending on the pathEnd parameter. If 'amount' is long enough, vertices may also be removed from the path.

uses
  Img32, Img32.Fmt.PNG, Img32.Vector, Img32.Draw;
...
var
  img: TImage32;
  pts: array [0..3] of TPointD;
  path, head, tail: TPathD;
  lineWidth, arrowHeadSize: integer;
begin
  pts[0] := PointD(20,20);
  pts[1] := PointD(130,20);
  pts[2] := PointD(130,240);
  pts[3] := PointD(240,240);
  lineWidth := 5;
  arrowHeadSize := GetDefaultArrowHeadSize(lineWidth);
  //create a curved path and then shorten it to accommodate arrow heads
  path := FlattenCBezier(pts[0], pts[1], pts[2], pts[3]);
  path := ShortenPath(path, peBothEnds, arrowHeadSize);
  //create the arrow heads
  tail := ArrowHead(pts[0], path[0], arrowHeadSize, asCircle);
  head := ArrowHead(pts[3], path[High(path)], arrowHeadSize, asFancy);

  //draw the path and the arrow heads
  img := TImage32.Create(256,256);
  DrawLine(img, path, lineWidth, clBlack32, esRound);
  DrawLine(img, tail, lineWidth, clBlack32, esPolygon);
  DrawLine(img, head, lineWidth, clBlack32, esPolygon);
  img.SaveToFile('arrow.png');
  img.Free;
    

See Also

TPathEnd