Tikz 形状像伞

Tikz 形状像伞

这是一种称为伞形法的乘法技巧。下图展示了两位数乘以两位数的乘法,例如96 \times 47。你能帮我画出下图吗?

在此处输入图片描述

如果图中还考虑了像这样的三位数乘法那就更好了464 \times 123

提前致谢。

答案1

它可能做得更容易,但这也可能有效:

\documentclass[border=1mm, tikz]{standalone}

% helper macro to split a string in to a comma separated list
\makeatletter
\newcommand{\makenumlist}[2]{%
    \def\splitnums##1##2\relax{%
        \edef#1{##1}%
        \@tfor\next:=##2\do{\edef#1{#1,\next}}%
    }%
    \splitnums#2\relax%
}
\makeatother

\newcounter{umbrellatip}
\newcommand{\umbrellamultiply}[2]{%
    \makenumlist{\firstfactornum}{#1}%
    \makenumlist{\secondfactornum}{#2}%
    \begin{tikzpicture}[font=\large]
        \setcounter{umbrellatip}{0}
        \foreach \n [count=\i] in \firstfactornum {
            \node (t\i) at (\i,0) {\n}; 
            \setcounter{umbrellatip}{\i}
        }
        \stepcounter{umbrellatip}
        \node (t\theumbrellatip) at (\theumbrellatip,0) {$\times$}; 
        \stepcounter{umbrellatip}
        \foreach \n [count=\i start from \theumbrellatip] in \secondfactornum {
            \node (t\i) at (\i,0) {\n}; 
            \setcounter{umbrellatip}{\i}
        }
        \foreach \t [count=\u start from 1] in {2,...,\theumbrellatip} {
            \draw (t\u.north) to[out=60, in=120] (t\t.north);
        }
        \draw (t1.north) to[out=60, in=120] coordinate (m) (t\theumbrellatip.north);
        \draw (m) -- (m |- 0,-20pt) arc (360:150:5pt);
    \end{tikzpicture}%
}

\begin{document}

\umbrellamultiply{96}{47}

\umbrellamultiply{464}{123}

\end{document}

在此处输入图片描述

在此处输入图片描述


更新:加排骨

\documentclass[border=1mm, tikz]{standalone}

% helper macro to split a string in to a comma separated list
\makeatletter
\newcommand{\makenumlist}[2]{%
    \def\splitnums##1##2\relax{%
        \edef#1{##1}%
        \@tfor\next:=##2\do{\edef#1{#1,\next}}%
    }%
    \splitnums#2\relax%
}
\makeatother

\newcounter{umbrellatip}
\newcommand{\umbrellamultiply}[2]{%
    \makenumlist{\firstfactornum}{#1}%
    \makenumlist{\secondfactornum}{#2}%
    \begin{tikzpicture}[font=\large]
        \setcounter{umbrellatip}{0}
        \foreach \n [count=\i] in \firstfactornum {
            \node (t\i) at (\i,0) {\n}; 
            \setcounter{umbrellatip}{\i}
        }
        \stepcounter{umbrellatip}
        \node (t\theumbrellatip) at (\theumbrellatip,0) {$\times$}; 
        \stepcounter{umbrellatip}
        \foreach \n [count=\i start from \theumbrellatip] in \secondfactornum {
            \node (t\i) at (\i,0) {\n}; 
            \setcounter{umbrellatip}{\i}
        }
        \foreach \t [count=\u start from 1] in {2,...,\theumbrellatip} {
            \draw (t\u.north) to[out=60, in=120] (t\t.north);
        }
        \draw (t1.north) to[out=60, in=120] coordinate (m) (t\theumbrellatip.north);
        \foreach \t [count=\v start from 2] in {3,...,\theumbrellatip} {
            \pgfmathtruncatemacro{\currenttip}{\v<(\theumbrellatip+1)/2 ? -1 : (\v>(\theumbrellatip+1)/2 ? 1 : 0)}
            \ifnum\currenttip>0\relax
                \draw (t\v.north) to[bend right] (m);
            \else
                \ifnum\currenttip<0\relax
                    \draw (t\v.north) to[bend left] (m);
                \fi
            \fi
        }
        \draw (m) -- (m |- 0,-20pt) arc (360:150:5pt);
    \end{tikzpicture}%
}

\begin{document}

\umbrellamultiply{96}{47}

\umbrellamultiply{464}{13}

\end{document}

在此处输入图片描述

在此处输入图片描述

相关内容