1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35:
| procedure DrawCubicCurve(Canvas: TCanvas; const Points: array of TPoint; Steps: cardinal);
function Interpolate(const p1, p2, p3, p4: TPoint; t: single): TPoint; function cubic(v1, v2, v3, v4, t: single): single; begin result:=v2+t*((-v1+v3)+t*((2*v1-2*v2+v3-v4)+t*(-v1+v2 - v3 + v4))); end;
begin Result.x:=round(cubic(p1.x, p2.x, p3.x, p4.x, t)); Result.y:=round(cubic(p1.y, p2.y, p3.y, p4.y, t)); end;
var i, s: integer; p, p1, p2, p3, p4: TPoint; begin if Length(Points) < 2 then exit; Canvas.MoveTo(Points[0].x, Points[0].y); p2:= Points[0]; p3:= Points[0]; p4:= Points[1]; for i:= 0 to High(Points)-1 do begin p1:= p2; p2:= p3; p3:= p4; if i+2 < Length(Points) then p4:= Points[i+2]; for s:= 1 to Steps do begin p:= Interpolate(p1, p2, p3, p4, s / Steps); Canvas.LineTo(p.x, p.y); end; end; end; |