线段如何画?

线段如何画?

使用@AboAmmar 的想法问题 # 374104在,我制作了下图:

在此处输入图片描述

\documentclass[12pt]{article}    
\usepackage[T1]{fontenc}    
\usepackage[latin1]{inputenc}     
\usepackage[brazil]{babel}    
\usepackage{tikz}    
\begin{document}

\begin{tikzpicture}[baseline=(n.base),decoration=bumps]    
\node[draw,ellipse,decorate](n){\textbf{Solução}};    
\end{tikzpicture}\\

\bigskip

\tikzset{     
  tr/.pic={       
    \draw[pattern=dots] (0,0) -- (0,4cm) -- (30:2cm) -- cycle;       
    \node at ($(0,0)!1.2!(30:2cm)$) {#1};
  }
}

\begin{center}    
\begin{tikzpicture}[scale=1]    
\path pic[rotate=  0]  at (4,0) {tr=S};    
\path pic[rotate= 90]  at (4,0) {tr=R};    
\path pic[rotate=-90]  at (0,4) {tr=Q};    
\path pic[rotate=180]  at (0,4) {tr=P};    
\path pic[rotate= 270]  at (0,0) {tr=};    
\path pic[rotate= -180]  at (4,4) {tr=};    
\path pic[rotate= -270]  at (4,4) {tr=};    
\path pic[rotate= -0]  at (0,0) {tr=};    
\end{tikzpicture}    
\end{center}

\end{document}

但是,我无法画出连接 P 和 S 的线段。该怎么办?

答案1

\documentclass[12pt]{article}

\usepackage{tikz}
\usetikzlibrary{calc}
\usetikzlibrary{patterns}

\begin{document}

\bigskip
\tikzset{
  tr/.pic={
    \draw[pattern=dots] (0,0) -- (0,4cm) -- (30:2cm) -- cycle;
    \draw[pattern=dots] (0,0) -- (0,4cm) -- ++(210:2cm) -- cycle;
    \node at ($(0,0)!1.2!(30:2cm)$) {#1};
    \coordinate (#1) at (30:2cm); } }

\begin{tikzpicture}[scale=1]
  \path pic[rotate= 0] at (4,0) {tr=S};
  \path pic[rotate= 90] at (4,0) {tr=R};
  \path pic[rotate=-90] at (0,4) {tr=Q};
  \path pic[rotate=180] at (0,4) {tr=P};
  \draw (P) -- (S);
\end{tikzpicture}

\end{document}

在此处输入图片描述

答案2

我尝试解释你的文字

\documentclass[12pt]{article}

\usepackage[T1]{fontenc}    

\usepackage[latin1]{inputenc}   

\usepackage[brazil]{babel} 

\usepackage{tikz}
\usetikzlibrary{calc,patterns,decorations}

\begin{document}

\tikzset{%
 tr/.pic={%
 \draw[pattern=dots] (0,0) -- (0,4cm) -- (30:2cm) -- cycle;
 \node at ($(0,0)!1.2!(30:2cm)$) {#1};
  }
}

    \begin{center}

\begin{tikzpicture}[scale=1]

\path pic[rotate=  0]  at (4,0) {tr=S};

\path pic[rotate= 90]  at (4,0) {tr=R};

\path pic[rotate=-90]  at (0,4) {tr=Q};

\path pic[rotate=180]  at (0,4) {tr=P};

\path pic[rotate= 270]  at (0,0) {tr=};

\path pic[rotate= -180]  at (4,4) {tr=};

\path pic[rotate= -270]  at (4,4) {tr=};

\path pic[rotate= -0]  at (0,0) {tr=};

\draw (-1.74,3) -- (5.74,1);

\end{tikzpicture}

\end{center}

\end{document}

在此处输入图片描述

答案3

使用键的简单自动解决方案。无需知道点或的coordinate坐标,图片将分别命名这些点和。然后一个简单的命令将连接这两个点。还请注意,图片现在绘制矩形。PSrecpointPpointSdrawrec

\documentclass[12pt]{article}
\usepackage{tikz}
\usetikzlibrary{calc, patterns}
\begin{document}

\tikzset{
 rec/.pic={
  \draw [pattern=dots](0,0) --(30:2cm)coordinate(point#1) --(0,4cm) --++(210:2cm) --cycle;
  \node at ($(0,0)!1.2!(35:2cm)$) {#1}; 
 } 
}

\begin{tikzpicture}[scale=1]
  \draw (0,0) rectangle (4,4);  
  \path pic[rotate=  0] at (4,0) {rec=S};
  \path pic[rotate= 90] at (4,0) {rec=R};
  \path pic[rotate=-90] at (0,4) {rec=Q};
  \path pic[rotate=180] at (0,4) {rec=P};
  \draw (pointS) -- (pointP);
\end{tikzpicture}

\end{document}

在此处输入图片描述

相关内容