procedure SmoothPath(const points: TPathD; isClosedPath: Boolean; tension: double = 0; shapeTolerance: double = 0.1): TPathD;
This function performs bicubic interpolation to convert discrete points in a path into a close approximation of a smooth curve. Paths may be open or closed.
tension: Range between -1 and 1 where -1 will produce the most curving, and +1 will produce the least (ie virtually no) curving.
shapeTolerance: the minimum distance a vertex can be from an imaginary line drawn between its two adjacent vertices (see SimplifyPaths).
uses Img32, Img32.Fmt.PNG, Img32.Draw, Img32.Extra;
...
var
i: integer;
img: TImage32;
path, smoothedPath: TPathD;
rec: TRect;
begin
path := MakePath([190,120, 240,160, 560,120, 190,490]);
// smooth closed path with normal smoothing
smoothedPath := SmoothPath(path, true, 0);
// smooth closed path with maximum smoothing
//smoothedPath := SmoothPath(path, true, -1);
rec := GetBounds(smoothedPath);
Types.InflateRect(rec, margin, margin);
path := TranslatePath(path, -rec.Left, -rec.Top);
smoothedPath :=
TranslatePath(smoothedPath, -rec.Left, -rec.Top);
img := TImage32.Create(rec.Width, rec.Height);
DrawLine(img, path, 1, clRed32, esClosed);
DrawLine(img, smoothedPath, 3, clBlue32, esClosed);
for i := 0 to High(path) do
DrawPoint(img, path[i], 3, clRed32);
img.SaveToFile('interpolation.png');
img.Free;
|
|
| with normal smoothing (0) | with maximum smoothing (-1) |
uses Img32, Img32.Fmt.PNG, Img32.Draw, Img32.Extra;
...
var
i: integer;
img: TImage32;
path, smoothedPath: TPathD;
rec: TRect;
begin
path := MakePath([10,100, 60,50, 110,50, 160,10, 210,100]);
// smooth open path with normal smoothing
smoothedPath := SmoothPath(path, false, 0);
rec := GetBounds(smoothedPath);
Types.InflateRect(rec, margin, margin);
path := TranslatePath(path, -rec.Left, -rec.Top);
smoothedPath := TranslatePath(smoothedPath, -rec.Left, -rec.Top);
img := TImage32.Create(rec.Width, rec.Height);
DrawLine( img, smoothedPath, 3, clBlue32, esRound, jsRound);
for i := 0 to High(path) do
DrawPoint(img, path[i], 3, clRed32);
img.SaveToFile('interpolation2.png');
img.Free;
Copyright ©2010-2023 Angus Johnson - Image32 4.8 - Help file built on 16 Apr 2025