// Win95/NT4.0 ºÎÅÍ º£Áê(Bezier) °î¼±À» ±×¸± ¼ö ÀÖ´Â API°¡ Ãß°¡µÇ¾ú½À´Ï´Ù
// ±×·¯³ª, Delphi ÀÇ TCanvas ¿¡¼´Â Áö¿øµÇÁö ¾Ê½À´Ï´Ù
// ¹°·Ð API ¸¦ Á÷Á¢ È£ÃâÇÏ¸é »ç¿ëÇÒ ¼ö ÀÖ½À´Ï´Ù
// ¾Æ·¡ ¿¹Á¦´Â PolyBezier() API ¸¦ »ç¿ëÇØ Ÿ¿øÀ» ±×¸®´Â ¿¹Á¦ÀÔ´Ï´Ù
// http://home.t-online.de/home/Robert.Rossmair/ellipse.htm ¸¦ Âü°íÇØ º¸¼¼¿ä
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCtrls;
type
TForm1 = class(TForm)
Image1: TImage;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
{
Ellipse approximation using N Bezier curves.
Relative approximation error <= (1-cos(Pi/N))3/(54*(1+cos(Pi/N)))
" " " < 4.25E-6 for N = 8
X, Y: Center coordinates
A, B: Half axis lengths
Angle: Angle in radians
}
procedure DrawEllipse(DC: hDC; X, Y, A, B, Angle: Double);
type
TFloatPoint = record
X, Y: Double;
end;
const
N = 8;
Alpha = Pi/N;
Beta = 0.26521648984; // = 4*(1-cos(Alpha))/(3*sin(Alpha))
var
P: array[0..N*3] of TFloatPoint;
Q: array[0..N*3] of TPoint; // N Bezier curves
SinA, CosA: Double;
Temp: Double;
I, J, K: Integer;
begin
for I := 0 to N-1 do
begin
Temp := I * (2*Alpha);
CosA := cos(Temp);
SinA := sin(Temp);
K := I*3;
if K = 0
then J := N*3-1
else J := K-1;
P[K].X := A * CosA;
P[K].Y := B * SinA;
SinA := Beta * A * SinA;
CosA := Beta * B * CosA;
P[J].X := P[K].X + SinA;
P[J].Y := P[K].Y - CosA;
P[K+1].X := P[K].X - SinA;
P[K+1].Y := P[K].Y + CosA;
end;
P[N*3] := P[0];
CosA := cos(Angle);
SinA := sin(Angle);
for i := Low(P) to High(P) do // Rotate and translate
begin
Q[I].X := Round(P[I].X*CosA - P[I].Y*SinA +X);
Q[I].Y := Round(P[I].X*SinA + P[I].Y*CosA +Y);
end;
// Draw ellipse and fill it using the current pen and brush
BeginPath(DC);
PolyBezier(DC, Q, High(Q)+1);
EndPath(DC);
StrokeAndFillPath(DC);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
DrawEllipse(Image1.Canvas.Handle,
Image1.Width div 2,
Image1.Height div 2,
40,
80,
20*(Pi/180)); // Angle 20
end;
end. |
|