TikZ:两个相互对应的图形

TikZ:两个相互对应的图形

现在我还没有开始制作这张图片,我想得到一些指点。任何制作图像的方法都足够了,可惜我更喜欢 TikZ 或tkz-euclide类似asympote

一根绳子长10米,我们把绳子切成两半,第一部分做成等边三角形,第二部分做成正方形。

用于三角形的部分长x米。

我的首选输出

我的问题是,我不知道如何根据三角形来改变正方形的大小。

例如,如果我说 2 米属于三角形。我如何让 TikZ 知道 8 米属于正方形?

答案1

\documentclass{scrartcl}   
\usepackage{tkz-euclide}
\usetkzobj{all}    
\begin{document}

\def\totallength{10}  

\foreach \len in {2,5,8} 
{%    
  \begin{tikzpicture}
    \tkzDefPoint(0,0){A};
    \tkzDefPoint(\len/3,0){B};  
    \tkzDefShiftPoint[B](0.5,0){C}; 
    \tkzDefShiftPoint[C](\totallength/4-\len/4,0){D}; 
    \tkzDrawTriangle[equilateral](A,B)   
    \tkzDrawSquare(C,D) 
 \end{tikzpicture}\par}

\end{document}  

在此处输入图片描述

答案2

\pgfmathsetmacro是你的朋友:

\documentclass[parskip]{scrartcl}
\usepackage[margin=15mm]{geometry}
\usepackage{tikz}

\begin{document}

\pgfmathsetmacro{\totallength}{10}

\begin{tikzpicture}
% --- only edit the next ---
\pgfmathsetmacro{\trianglelength}{2}
% --- --- --- --- --- --- --- ---
\pgfmathsetmacro{\triangleside}{\trianglelength/3}
\pgfmathsetmacro{\squarelength}{\totallength-\trianglelength}
\pgfmathsetmacro{\squareside}{\squarelength/4}
\draw (-0.1,0) -- ++(180:\triangleside) -- ++(60:\triangleside) -- cycle;
\draw (0.1,0) rectangle ++(\squareside,\squareside);
\end{tikzpicture}

\begin{tikzpicture}
% --- only edit the next ---
\pgfmathsetmacro{\trianglelength}{5}
% --- --- --- --- --- --- --- ---
\pgfmathsetmacro{\triangleside}{\trianglelength/3}
\pgfmathsetmacro{\squarelength}{\totallength-\trianglelength}
\pgfmathsetmacro{\squareside}{\squarelength/4}
\draw (-0.1,0) -- ++(180:\triangleside) -- ++(60:\triangleside) -- cycle;
\draw (0.1,0) rectangle ++(\squareside,\squareside);
\end{tikzpicture}

\begin{tikzpicture}
% --- only edit the next ---
\pgfmathsetmacro{\trianglelength}{8}
% --- --- --- --- --- --- --- ---
\pgfmathsetmacro{\triangleside}{\trianglelength/3}
\pgfmathsetmacro{\squarelength}{\totallength-\trianglelength}
\pgfmathsetmacro{\squareside}{\squarelength/4}
\draw (-0.1,0) -- ++(180:\triangleside) -- ++(60:\triangleside) -- cycle;
\draw (0.1,0) rectangle ++(\squareside,\squareside);
\end{tikzpicture}

\end{document}

在此处输入图片描述

相关内容