Skip to content

Algorithme de tirage au sort TikZ/PGF

Nos programmeurs vedettes ont épuisé leurs réserves de café, cherchant jour et nuit la solution, jusqu'à ce qu'Emilia trouve la solution dans Gogs, alors maintenant elle la partage ici.

Solution :

Comme le souligne JouleV, l'ellipse est dessinée en quatre courbes de Bézier. Si vous ne voulez pas chercher ces choses dans le code, vous pouvez toujours utiliser... show path construction pour voir comment le chemin est construit.

documentclass[tikz,border=3.14mm]{standalone}
usetikzlibrary{decorations.pathreplacing}
begin{document}
begin{tikzpicture}[decoration={show path construction, % see p. 634 of the pgfmanual
    moveto code={
      fill [red] (tikzinputsegmentfirst) circle (2pt)
        node [fill=none, below] {moveto};},
    lineto code={
      draw [blue,->] (tikzinputsegmentfirst) -- (tikzinputsegmentlast)
        node [above] {lineto};
    },
    curveto code={
      draw [green!75!black,->] (tikzinputsegmentfirst) .. controls
        (tikzinputsegmentsupporta) and (tikzinputsegmentsupportb)
        ..(tikzinputsegmentlast) node [above] {curveto};
    },
    closepath code={
      draw [orange,->] (tikzinputsegmentfirst) -- (tikzinputsegmentlast)
        node [above] {closepath};}
}]
draw [rotate around={0.:(0.,0.)},line width=0.8pt,postaction=decorate] (0.,0.) ellipse (5.cm and 4.cm);
end{tikzpicture}
end{document}

enter image description here

C'est également vrai pour les cercles, c'est pourquoi la rotation d'un cercle peut modifier sa boîte englobante.

pgfcorepathconstruct.code.tex, lignes 892-1010 :

% Append  an ellipse to the current path.
%
% #1 = center
% #2 = first axis
% #3 = second axis
%
% Example:
%
% % Add a circle of radius 3cm around the origin
% pgfpathellipse{pgforigin}{pgfxy(2,0)}{pgfxy(0,1)}
%
% % Draw a non-filled circle of radius 1cm around the point (1,1)
% pgfpathellipse{pgfxy(1,1)}{pgfxy(1,1)}{pgfxy(-2,2)}
% pgfstroke

defpgfpathellipse#1#2#3{%
  pgfpointtransformed{#1}% store center in xc/yc
  [email protected]=[email protected]%
  [email protected]=[email protected]%
  pgfpointtransformed{#2}%
  [email protected]=[email protected]% store first axis in xa/ya
  [email protected]=[email protected]%
  advance[email protected] by-[email protected]@x%
  advance[email protected] by-[email protected]@y%
  pgfpointtransformed{#3}%
  [email protected]=[email protected]% store second axis in xb/yb
  [email protected]=[email protected]%
  advance[email protected] by-[email protected]@x%
  advance[email protected] by-[email protected]@y%
  {%
    advance[email protected] by[email protected]%
    advance[email protected] by[email protected]%
    [email protected]@moveto{[email protected]}{[email protected]}%
  }%
  [email protected]=0.55228475[email protected]% first arc
  [email protected]=0.55228475[email protected]%
  advance[email protected] by[email protected]%
  advance[email protected] by[email protected]%
  advance[email protected] by[email protected]%
  advance[email protected] by[email protected]%
  edef[email protected]{[email protected]the[email protected][email protected]the[email protected]}%
  [email protected]=0.55228475[email protected]%
  [email protected]=0.55228475[email protected]%
  advance[email protected] by[email protected]%
  advance[email protected] by[email protected]%
  {%
    advance[email protected] by[email protected]%
    advance[email protected] by[email protected]%
    advance[email protected] by[email protected]%
    advance[email protected] by[email protected]%
    [email protected]%
    [email protected]@curveto{[email protected]}{[email protected]}{[email protected]}{[email protected]}{[email protected]}{[email protected]}%
  }%
  [email protected]=-[email protected]% flip first axis
  [email protected]=-[email protected]%
  [email protected]=0.55228475[email protected]% second arc
  [email protected]=0.55228475[email protected]%
  advance[email protected] by[email protected]%
  advance[email protected] by[email protected]%
  advance[email protected] by[email protected]%
  advance[email protected] by[email protected]%
  edef[email protected]{[email protected]the[email protected][email protected]the[email protected]}%
  [email protected]=0.55228475[email protected]%
  [email protected]=0.55228475[email protected]%
  advance[email protected] by[email protected]%
  advance[email protected] by[email protected]%
  {%
    advance[email protected] by[email protected]%
    advance[email protected] by[email protected]%
    advance[email protected] by[email protected]%
    advance[email protected] by[email protected]%
    [email protected]%
    [email protected]@curveto{[email protected]}{[email protected]}{[email protected]}{[email protected]}{[email protected]}{[email protected]}%
  }%
  [email protected]=-[email protected]% flip second axis
  [email protected]=-[email protected]%
  [email protected]=0.55228475[email protected]% third arc
  [email protected]=0.55228475[email protected]%
  advance[email protected] by[email protected]%
  advance[email protected] by[email protected]%
  advance[email protected] by[email protected]%
  advance[email protected] by[email protected]%
  edef[email protected]{[email protected]the[email protected][email protected]the[email protected]}%
  [email protected]=0.55228475[email protected]%
  [email protected]=0.55228475[email protected]%
  advance[email protected] by[email protected]%
  advance[email protected] by[email protected]%
  {%
    advance[email protected] by[email protected]%
    advance[email protected] by[email protected]%
    advance[email protected] by[email protected]%
    advance[email protected] by[email protected]%
    [email protected]%
    [email protected]@curveto{[email protected]}{[email protected]}{[email protected]}{[email protected]}{[email protected]}{[email protected]}%
  }%
  [email protected]=-[email protected]% flip first axis once more
  [email protected]=-[email protected]%
  [email protected]=0.55228475[email protected]% fourth arc
  [email protected]=0.55228475[email protected]%
  advance[email protected] by[email protected]%
  advance[email protected] by[email protected]%
  advance[email protected] by[email protected]%
  advance[email protected] by[email protected]%
  edef[email protected]{[email protected]the[email protected][email protected]the[email protected]}%
  [email protected]=0.55228475[email protected]%
  [email protected]=0.55228475[email protected]%
  advance[email protected] by[email protected]%
  advance[email protected] by[email protected]%
  {%
    advance[email protected] by[email protected]%
    advance[email protected] by[email protected]%
    advance[email protected] by[email protected]%
    advance[email protected] by[email protected]%
    [email protected]%
    [email protected]@curveto{[email protected]}{[email protected]}{[email protected]}{[email protected]}{[email protected]}{[email protected]}%
  }%
  [email protected]@closepath%
  [email protected]@moveto{[email protected]}{[email protected]}%
}

Eh bien, rien qu'en lisant les commentaires qui s'y trouvent, vous saurez que l'on ne peut pas faire autrement. ellipse est dessinée par quatre courbes différentes (chaque courbe est dessinée avec une courbe [email protected]@curveto).

Notez que la même chose se produit avec circle.

Si notre article vous a été utile, nous apprécierions que vous le partagiez avec le reste des développeurs, vous contribuerez ainsi à diffuser cette information.



Utilisez notre moteur de recherche

Ricerca
Generic filters

Laisser un commentaire

Votre adresse e-mail ne sera pas publiée.