{-- FCooPtStarDavid2d ----------------------------------------------------------
Calcule les coordonnées des douze sommets d'une étoile de David en 2D à partir
des coordonnées du Centre de gravité
Entrées : CG(x,y)
: R rayon du cercle qui circonsrit l'étoile
Sorties : S1(x1,y1)..S12(x12,y12)
-------------------------------------------------------------------------------}
Function FCooPtStarDavid2d (CG : Tpoint; R : LongInt) : T12Points;
var H : extended; // H hauteur du triangle equilatéral des étoiles internes
a : Extended; // a = longueur d'une branche de l'étoile
begin
H := R / 2;
a := R / sqrt(3);
Result[1].X := Round(CG.X + a);
Result[1].Y := CG.Y;
Result[2].X := Round(CG.X + 1.5 * a);
Result[2].Y := Round(CG.Y + H);
Result[3].X := Round(CG.X + a / 2);
Result[3].Y := Result[2].Y;
Result[4].X := CG.X;
Result[4].Y := Round(CG.Y + R);
Result[5].X := Round(CG.X - a / 2);
Result[5].Y := Result[2].Y;
Result[6].X := Round(CG.X - 1.5 * a);
Result[6].Y := Result[2].Y;
Result[7].X := Round(CG.X - a);
Result[7].Y := CG.Y;
Result[8].X := Result[6].X;
Result[8].Y := Round(CG.Y - H);
Result[9].X := Result[5].X;
Result[9].Y := Result[8].Y;
Result[10].X := CG.X;
Result[10].Y := Round(CG.Y - R);
Result[11].X := Result[3].X;
Result[11].Y := Result[8].Y;
Result[12].X := Result[2].X;
Result[12].Y := Result[8].Y;
end;
Exemple :
{ ETOILE DE DAVID --------------------------------------------------------------
Ox,Oy : Centre de la figure
R : rayon du cercle circoncrit de l'étoile
e : épaisseur de la ligne entourant la figure
aCanvas : Canvas désigné sur laquelle la figure sera déssinée
aColorExt : Couleur du trait extérieur
aColorIt : Couleur intérieure
------------------------------------------------------------------------------}
procedure Draw_StarDavid(Ox,Oy,R,e : Word;aAngle : Real; aCanvas : TCanvas;aColorExt,aColorInt: Tcolor);
var CooSomStar : T12Points; // coordonnées des 12 sommets
begin
CooSomStar := FCooPtStarDavid2d (Point(Ox,Oy),R);
With aCanvas do
begin
Brush.Color := aColorInt;
Brush.Style := bsSolid;
Pen.Color := aColorExt;
Pen.Style := psSolid;
Pen.Width := e;
Polygon([Point(CooSomStar[1].X, CooSomStar[1].Y),
Point(CooSomStar[2].X, CooSomStar[2].Y),
Point(CooSomStar[3].X, CooSomStar[3].Y),
Point(CooSomStar[4].X, CooSomStar[4].Y),
Point(CooSomStar[5].X, CooSomStar[5].Y),
Point(CooSomStar[6].X, CooSomStar[6].Y),
Point(CooSomStar[7].X, CooSomStar[7].Y),
Point(CooSomStar[8].X, CooSomStar[8].Y),
Point(CooSomStar[9].X, CooSomStar[9].Y),
Point(CooSomStar[10].X, CooSomStar[10].Y),
Point(CooSomStar[11].X, CooSomStar[11].Y),
Point(CooSomStar[12].X, CooSomStar[12].Y)] );
end;
end;