From: "Boris Novgorodov" Newsgroups: borland.public.delphi.graphics References: <3e55966f$1@newsgroups.borland.com> Subject: Re: Rounded Corners Date: Fri, 21 Feb 2003 12:58:35 +0600 Lines: 60 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2600.0000 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 NNTP-Posting-Host: 193.124.164.57 Message-ID: <3e55ce21@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1045810721 193.124.164.57 (20 Feb 2003 22:58:41 -0800) Path: newsgroups.borland.com!not-for-mail Xref: newsgroups.borland.com borland.public.delphi.graphics:56476 procedure TForm1.Button1Click(Sender: TObject); procedure DrawRoundPolygon(Verts: array of TPoint; Dist: Integer; Coeff: Double = 0.5); var Pts: array[0..3] of TPoint; len, TmpD: double; i, dx, dy, np, next, nextnext: integer; begin np := High(Verts) + 1; for i := 0 to np - 1 do begin next := (i + 1) mod np; nextnext := (i + 2) mod np; dx := Verts[next].x - Verts[i].x; dy := Verts[next].y - Verts[i].y; len := Sqrt(Sqr(dx) + Sqr(dy)); TmpD := MinValue([len / 3, Dist]); Pts[0].X := Verts[next].x - Round(TmpD * dx / len); Pts[0].Y := Verts[next].y - Round(TmpD * dy / len); Pts[1].X := Verts[next].x - Round(Coeff * TmpD * dx / len); Pts[1].Y := Verts[next].y - Round(Coeff * TmpD * dy / len); Canvas.MoveTo(Verts[i].x + Round(TmpD * dx / len), Verts[i].y + Round(TmpD * dy / len)); Canvas.LineTo(Pts[0].X, Pts[0].Y); dx := Verts[nextnext].x - Verts[next].x; dy := Verts[nextnext].y - Verts[next].y; len := Sqrt(Sqr(dx) + Sqr(dy)); TmpD := MinValue([len / 3, Dist]); Pts[3].X := Verts[next].x + Round(TmpD * dx / len); Pts[3].Y := Verts[next].y + Round(TmpD * dy / len); Pts[2].X := Verts[next].x + Round(Coeff * TmpD * dx / len); Pts[2].Y := Verts[next].y + Round(Coeff * TmpD * dy / len); Canvas.PolyBezier(Pts); end; end; begin Canvas.Pen.Color := clRed; Canvas.Pen.Width := 2; DrawRoundPolygon([Point(20, 300), Point(320, 300), Point(120, 100)], 30); end; Try different Coeff (negative for interesting effect ;) ) Another way - create Pen with PS_JOIN_ROUND (suitable for wide pen) -- Regards Boris Novgorodov > Anyone know how to draw shapes like triangles with rounded > corners. My algorithms seem overly complicated and involve many > trig calculations. Someone out there must know a simple formula to figure it out.