castelli in tikz

  • Creatore
    Topic
  • #92729
    claudio
    Partecipante
      Up
      0
      Down
      ::


      I castelli sono quelli del buon Ruffini
      in questa prima versione ho badato a disegnarne uno semplice
      ecco il codice
      `
      \documentclass[11pt]{minimal}
      \usepackage{tikz}
      \usetikzlibrary{arrows}
      \begin{document}
      \begin{tikzpicture}
      \tikzset{tondo/.style={draw,circle,minimum width=2.5em}};
      \tikzset{notondo/.style={circle,minimum width=2.5em}};
      \tikzset{freccia/.style={-triangle 90,very thick}};
      \tikzstyle{etichetta}=[midway,fill=black!20]

      %A
      \pgfmathsetmacro{\xa}{0};
      \pgfmathsetmacro{\ya}{0};
      %B
      \pgfmathsetmacro{\xb}{4};
      \pgfmathsetmacro{\yb}{\ya};
      %C
      \pgfmathsetmacro{\xc}{\xb};
      \pgfmathsetmacro{\yc}{3};
      %D
      \pgfmathsetmacro{\xd}{\xa};
      \pgfmathsetmacro{\yd}{\yc};
      \pgfmathsetmacro{\deltac}{1.5};
      \pgfmathsetmacro{\deltar}{1};
      \draw(\xa-\deltar,\ya)–(\xb+\deltar,\yb);
      \draw(\xb,\yb-\deltac)–(\xc,\yc+\deltac);
      \draw(\xc+\deltar,\yc)–(\xd-\deltar,\yd);
      \draw(\xd,\yd+\deltac)–(\xa,\ya-\deltac);

      \node[tondo] (A1) at (1,3.5) {$1$};
      \node[tondo] (A2) at (3,3.5) {$2$};
      \node[tondo] (AT) at (4.5,3.5) {$1$};

      \node[tondo] (D1) at (-0.5,0.5) {$-1$};
      \node[tondo] (M2) at (3,0.5) {$-1$};
      \node[tondo] (MR) at (4.5,0.5) {$-1$};

      \node[tondo] (B1) at (1,-1.2) {$1$};
      \node[tondo] (B2) at (3,-1.2) {$1$};
      \node[tondo] (R) at (4.5,-1.2) {$0$};

      \draw [freccia] (A1)–(B1);
      \draw [freccia] (D1)–(B1) node[etichetta]{$*$};
      \draw [freccia] (B1)–(M2) node[etichetta]{$=$};
      \draw [freccia] (A2)–(M2)node[etichetta]{$+$};
      \draw [freccia] (M2)–(B2)node[etichetta]{$=$};;
      \draw [freccia] (D1)–(B2)node[etichetta]{$*$};;
      \draw [freccia] (B2)–(MR)node[etichetta]{$=$};;
      \draw [freccia] (AT)–(MR)node[etichetta]{$+$};;
      \draw [freccia] (MR)–(R)node[etichetta]{$=$};;
      \end{tikzpicture}
      \end{document}
      `

      in questa seconda versione ho cercato di generalizzare il codice in modo
      da poterlo utilizzare con polinomi di grado superiore.

      `
      \documentclass[11pt]{minimal}
      \usepackage{tikz}
      \usetikzlibrary{arrows}
      \begin{document}
      \begin{tikzpicture}
      \tikzset{tondo/.style={draw,circle,minimum width=2.5em}};
      \tikzset{notondo/.style={circle,minimum width=2.5em}};
      \tikzset{freccia/.style={-triangle 90,very thick}};
      \tikzstyle{etichetta}=[midway,fill=black!20]

      \pgfmathsetmacro{\np}{2};

      %A
      \pgfmathsetmacro{\xa}{0};
      \pgfmathsetmacro{\ya}{0};
      %B
      \pgfmathsetmacro{\xb}{\np*2};
      \pgfmathsetmacro{\yb}{\ya};
      %C
      \pgfmathsetmacro{\xc}{\xb};
      \pgfmathsetmacro{\yc}{3};
      %D
      \pgfmathsetmacro{\xd}{\xa};
      \pgfmathsetmacro{\yd}{\yc};
      %disegno righe castello
      \pgfmathsetmacro{\extrac}{1.5};
      \pgfmathsetmacro{\extrar}{1};
      \draw(\xa-\extrar,\ya)–(\xb+\extrar,\yb);
      \draw(\xb,\yb-\extrac)–(\xc,\yc+\extrac);
      \draw(\xc+\extrar,\yc)–(\xd-\extrar,\yd);
      \draw(\xd,\yd+\extrac)–(\xa,\ya-\extrac);
      %aggiustamento punti prima riga
      \pgfmathsetmacro{\deltaa}{3.5};
      %posizionamento coefficienti in alto
      \foreach \x/\co in{1/1,
      3/2,
      4.5/1}
      \draw(\x,\deltaa) node[tondo] {\co};

      \pgfmathsetmacro{\deltam}{0.5};
      %posizionamento coefficienti in mezzo
      \foreach \x/\co in{-0.5/-1
      ,3/-1,
      4.5/-1}
      \draw(\x,\deltam) node[tondo] {\co};

      \pgfmathsetmacro{\deltab}{-1.2};
      %posizionamento coefficienti in mezzo
      \foreach \x/\co in{1/1
      ,3/1
      ,4.5/1}
      \draw(\x,\deltab) node[tondo] {\co};
      \draw [freccia] (1,\deltaa)–(1,\deltab);

      \end{tikzpicture}
      \end{document}
      `

      Tutto va bene finché non cerco di collegare
      i punti con le frecce per indicare i passaggi
      il perché è ovvio
      nel primo esempio sono nodi nel secondo punti
      e l’effetto estetico non è uguale
      come rimediare ?
      ciao
      claudio

    Visualizzazione 3 filoni di risposte
    • Autore
      Risposte
      • #92730
        Up
        0
        Down
        ::

        claudio” post=92321I castelli sono quelli del buon Ruffini
        in questa prima versione ho badato a disegnarne uno semplice
        ecco il codice
        `
        \documentclass[11pt]{minimal}
        \usepackage{tikz}
        \usetikzlibrary{arrows}
        \begin{document}
        \begin{tikzpicture}
        \tikzset{tondo/.style={draw,circle,minimum width=2.5em}};
        \tikzset{notondo/.style={circle,minimum width=2.5em}};
        \tikzset{freccia/.style={-triangle 90,very thick}};
        \tikzstyle{etichetta}=[midway,fill=black!20]

        %A
        \pgfmathsetmacro{\xa}{0};
        \pgfmathsetmacro{\ya}{0};
        %B
        \pgfmathsetmacro{\xb}{4};
        \pgfmathsetmacro{\yb}{\ya};
        %C
        \pgfmathsetmacro{\xc}{\xb};
        \pgfmathsetmacro{\yc}{3};
        %D
        \pgfmathsetmacro{\xd}{\xa};
        \pgfmathsetmacro{\yd}{\yc};
        \pgfmathsetmacro{\deltac}{1.5};
        \pgfmathsetmacro{\deltar}{1};
        \draw(\xa-\deltar,\ya)–(\xb+\deltar,\yb);
        \draw(\xb,\yb-\deltac)–(\xc,\yc+\deltac);
        \draw(\xc+\deltar,\yc)–(\xd-\deltar,\yd);
        \draw(\xd,\yd+\deltac)–(\xa,\ya-\deltac);

        \node[tondo] (A1) at (1,3.5) {$1$};
        \node[tondo] (A2) at (3,3.5) {$2$};
        \node[tondo] (AT) at (4.5,3.5) {$1$};

        \node[tondo] (D1) at (-0.5,0.5) {$-1$};
        \node[tondo] (M2) at (3,0.5) {$-1$};
        \node[tondo] (MR) at (4.5,0.5) {$-1$};

        \node[tondo] (B1) at (1,-1.2) {$1$};
        \node[tondo] (B2) at (3,-1.2) {$1$};
        \node[tondo] (R) at (4.5,-1.2) {$0$};

        \draw [freccia] (A1)–(B1);
        \draw [freccia] (D1)–(B1) node[etichetta]{$*$};
        \draw [freccia] (B1)–(M2) node[etichetta]{$=$};
        \draw [freccia] (A2)–(M2)node[etichetta]{$+$};
        \draw [freccia] (M2)–(B2)node[etichetta]{$=$};;
        \draw [freccia] (D1)–(B2)node[etichetta]{$*$};;
        \draw [freccia] (B2)–(MR)node[etichetta]{$=$};;
        \draw [freccia] (AT)–(MR)node[etichetta]{$+$};;
        \draw [freccia] (MR)–(R)node[etichetta]{$=$};;
        \end{tikzpicture}
        \end{document}
        `

        in questa seconda versione ho cercato di generalizzare il codice in modo
        da poterlo utilizzare con polinomi di grado superiore.

        `
        \documentclass[11pt]{minimal}
        \usepackage{tikz}
        \usetikzlibrary{arrows}
        \begin{document}
        \begin{tikzpicture}
        \tikzset{tondo/.style={draw,circle,minimum width=2.5em}};
        \tikzset{notondo/.style={circle,minimum width=2.5em}};
        \tikzset{freccia/.style={-triangle 90,very thick}};
        \tikzstyle{etichetta}=[midway,fill=black!20]

        \pgfmathsetmacro{\np}{2};

        %A
        \pgfmathsetmacro{\xa}{0};
        \pgfmathsetmacro{\ya}{0};
        %B
        \pgfmathsetmacro{\xb}{\np*2};
        \pgfmathsetmacro{\yb}{\ya};
        %C
        \pgfmathsetmacro{\xc}{\xb};
        \pgfmathsetmacro{\yc}{3};
        %D
        \pgfmathsetmacro{\xd}{\xa};
        \pgfmathsetmacro{\yd}{\yc};
        %disegno righe castello
        \pgfmathsetmacro{\extrac}{1.5};
        \pgfmathsetmacro{\extrar}{1};
        \draw(\xa-\extrar,\ya)–(\xb+\extrar,\yb);
        \draw(\xb,\yb-\extrac)–(\xc,\yc+\extrac);
        \draw(\xc+\extrar,\yc)–(\xd-\extrar,\yd);
        \draw(\xd,\yd+\extrac)–(\xa,\ya-\extrac);
        %aggiustamento punti prima riga
        \pgfmathsetmacro{\deltaa}{3.5};
        %posizionamento coefficienti in alto
        \foreach \x/\co in{1/1,
        3/2,
        4.5/1}
        \draw(\x,\deltaa) node[tondo] {\co};

        \pgfmathsetmacro{\deltam}{0.5};
        %posizionamento coefficienti in mezzo
        \foreach \x/\co in{-0.5/-1
        ,3/-1,
        4.5/-1}
        \draw(\x,\deltam) node[tondo] {\co};

        \pgfmathsetmacro{\deltab}{-1.2};
        %posizionamento coefficienti in mezzo
        \foreach \x/\co in{1/1
        ,3/1
        ,4.5/1}
        \draw(\x,\deltab) node[tondo] {\co};
        \draw [freccia] (1,\deltaa)–(1,\deltab);

        \end{tikzpicture}
        \end{document}
        `

        Tutto va bene finché non cerco di collegare
        i punti con le frecce per indicare i passaggi
        il perché è ovvio
        nel primo esempio sono nodi nel secondo punti
        e l’effetto estetico non è uguale
        come rimediare ?
        ciao
        claudio

        Si, nel secondo esempio colleghi usando coordinate sebbene i cerchi siano comunque dei nodi. Quello che devi fare, quindi, è trovare un sistema per dare un nome univoco ai nodi così da poter continuare a fare i collegamenti come nel primo disegno.

        Ciao
        Claudio

      • #92731
        claudio
        Partecipante
          Up
          0
          Down
          ::


          colto il suggerimento ho risolto cosi
          ma l’ultimo ciclo non funziona
          perchè
          `
          \begin{tikzpicture}
          \tikzset{tondo/.style={draw,circle,minimum width=2.5em}};
          \tikzset{notondo/.style={circle,minimum width=2.5em}};
          \tikzset{freccia/.style={-triangle 90,very thick}};
          \tikzstyle{etichetta}=[midway,fill=black!20]

          \pgfmathsetmacro{\np}{2};

          %A
          \pgfmathsetmacro{\xa}{0};
          \pgfmathsetmacro{\ya}{0};
          %B
          \pgfmathsetmacro{\xb}{\np*2};
          \pgfmathsetmacro{\yb}{\ya};
          %C
          \pgfmathsetmacro{\xc}{\xb};
          \pgfmathsetmacro{\yc}{3};
          %D
          \pgfmathsetmacro{\xd}{\xa};
          \pgfmathsetmacro{\yd}{\yc};
          %disegno righe castello
          \pgfmathsetmacro{\extrac}{1.5};
          \pgfmathsetmacro{\extrar}{1};
          \draw(\xa-\extrar,\ya)–(\xb+\extrar,\yb);
          \draw(\xb,\yb-\extrac)–(\xc,\yc+\extrac);
          \draw(\xc+\extrar,\yc)–(\xd-\extrar,\yd);
          \draw(\xd,\yd+\extrac)–(\xa,\ya-\extrac);
          %aggiustamento punti prima riga
          \pgfmathsetmacro{\deltaa}{3.5};
          %posizionamento coefficienti in alto
          \foreach \n/\x/\co in{
          a1/1/1,
          a2/3/2,
          a3/4.5/1}
          %\draw(\x,\deltaa) node[tondo] {\co};
          \node[tondo] (\n) at (\x,\deltaa){\co};

          \pgfmathsetmacro{\deltam}{0.5};
          %posizionamento coefficienti in mezzo
          \foreach \n/\x/\co in{
          m1/-0.5/-1,
          m2/3/-1,
          m3/4.5/-1}
          \node[tondo] (\n) at (\x,\deltam){\co};

          \pgfmathsetmacro{\deltab}{-1.2};
          %posizionamento coefficienti in mezzo
          \foreach \n/\x/\co in{
          b1/1/1,
          b2/3/1,
          b3/4.5/1}
          \node[tondo] (\n) at (\x,deltab){\co};
          \foreach \a/\b in{
          a1/b1,
          m1/b1
          }
          \draw[freccia](\a)–(\b);
          \end{tikzpicture}
          `
          in allegato quello che vorrei ottenere
          (non riporto il codice perché troppo ingombrante)
          in cui i cerchietti e le frecce vengono accesi a bisogna
          mi sa che in metodo a mano è la via migliore
          ciao

          Attachments:
          You must be logged in to view attached files.
        • #92732
          Up
          0
          Down
          ::


          È un errorino subdolo in effetti 🙂

          Ma, come prima cosa ti segnalo che `\node[tondo] (\n) at (\x,deltab){\co};` genera un errore in quanto serve [tt]\deltab[/tt]. Passando all’errore, si presenta in `
          \foreach \a/\b in{
          a1/b1,
          m1/b1
          }
          ` perché dopo [tt]b1[/tt] c’è uno spazio. Quindi hai due possibilità: `
          \foreach \a/\b in{
          a1/b1,
          m1/b1% elimina lo spazio spurio
          }
          ` oppure: `
          \foreach \a/\b in{
          a1/b1,
          m1/b1}
          `

          Ciao
          Claudio

        • #92733
          claudio
          Partecipante
            Up
            0
            Down
            ::


            penso che ora ci siamo
            ho inserito come variabile anche gli stili
            è corretta la definizione dello stile che non definisce niente?
            ecco il codice credo finale
            `
            \documentclass[11pt]{minimal}
            \usepackage{tikz}
            \usetikzlibrary{arrows}
            \begin{document}
            \begin{tikzpicture}
            \tikzset{tondo/.style={draw,circle,minimum width=2.5em}};
            \tikzset{notondo/.style={circle,minimum width=2.5em}};
            \tikzset{freccia/.style={-triangle 90,very thick}};
            \tikzstyle{etichetta}=[midway,fill=black!20]
            \tikzstyle{noetichetta}=[]

            \pgfmathsetmacro{\np}{2};

            %A
            \pgfmathsetmacro{\xa}{0};
            \pgfmathsetmacro{\ya}{0};
            %B
            \pgfmathsetmacro{\xb}{\np*2};
            \pgfmathsetmacro{\yb}{\ya};
            %C
            \pgfmathsetmacro{\xc}{\xb};
            \pgfmathsetmacro{\yc}{3};
            %D
            \pgfmathsetmacro{\xd}{\xa};
            \pgfmathsetmacro{\yd}{\yc};
            %disegno righe castello
            \pgfmathsetmacro{\extrac}{1.5};
            \pgfmathsetmacro{\extrar}{1};
            \draw(\xa-\extrar,\ya)–(\xb+\extrar,\yb);
            \draw(\xb,\yb-\extrac)–(\xc,\yc+\extrac);
            \draw(\xc+\extrar,\yc)–(\xd-\extrar,\yd);
            \draw(\xd,\yd+\extrac)–(\xa,\ya-\extrac);
            %aggiustamento punti prima riga
            \pgfmathsetmacro{\deltaa}{3.5};
            %posizionamento coefficienti in alto
            \foreach \n/\x/\st/\co in{
            a1/1/notondo/1,
            a2/3/notondo/2,
            a3/4.5/notondo/1}
            %\draw(\x,\deltaa) node[tondo] {\co};
            \node[\st] (\n) at (\x,\deltaa){\co};

            \pgfmathsetmacro{\deltam}{0.5};
            %posizionamento coefficienti in mezzo
            \foreach \n/\x/\st/\co in{
            m1/-0.5/notondo/-1,
            m2/3/notondo/-1,
            m3/4.5/notondo/-1}
            \node[\st] (\n) at (\x,\deltam){\co};

            \pgfmathsetmacro{\deltab}{-1.2};
            %posizionamento coefficienti in mezzo
            \foreach \n/\x/\st/\co in{
            b1/1/notondo/1,
            b2/3/notondo/1,
            b3/4.5/notondo/1}
            \node[\st] (\n) at (\x,\deltab){\co};
            \foreach \a/\b/\st/\op in{
            a1/b1/noetichetta/,
            m1/b1/etichetta/*,
            b1/m2/etichetta/=%
            }
            \draw[freccia](\a)–(\b)node[\st]{$\op$};
            \end{tikzpicture}
            \end{document}
            `

            saluti
            claudio

        Visualizzazione 3 filoni di risposte
        • Devi essere connesso per rispondere a questo topic.

        Go to top