旋转矩形中点之间的矩形

旋转矩形中点之间的矩形

我需要在两个旋转的矩形的中点之间画一个矩形(如下所示)。

我该怎么做呢?

我的当前代码显示如下。

当前代码

\draw[thick] (0,0) -- (6,0);
\draw[thick,fill=yellow!40, rotate around={26.5:(3.1,-5)}] (3,0) rectangle (3.2,-5);
\draw[thick,fill=yellow!40, rotate around={-26.5:(3.1,-5)}] (3,0) rectangle (3.2,-5);
\draw[fill=black] (3.1,-5) circle(0.11);
\node at (3.1,-5.3) {A};

当前结果

在此处输入图片描述

想要的结果的模型

在此处输入图片描述

答案1

只需定义两个coordinatesa 和 b,然后绘制一条具有所需粗细的线。pos根据需要更改值。

\documentclass[tikz,border=5]{standalone}
\begin{document}
  \begin{tikzpicture}
    \draw[thick] (0,0) -- (6,0);
\draw[thick,fill=yellow!40, rotate around={26.5:(3.1,-5)}] (3,0) rectangle (3.2,-5)coordinate[pos=0.5](a);
\draw[thick,fill=yellow!40, rotate around={-26.5:(3.1,-5)}] (3,0) rectangle (3.2,-5)coordinate[pos=0.5](b);
\draw[fill=black] (3.1,-5) circle(0.11);
\node at (3.1,-5.3) {A};
\draw[line width=2pt] (a) -- (b);
  \end{tikzpicture}
\end{document}

在此处输入图片描述

答案2

相反,rectangles您可以绘制矩形nodes并参考其center锚点。

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

\begin{document}

\begin{tikzpicture}
\draw[thin,gray] (0,0) node[above] {(0,0)} grid (6,-6) node[below] {(6,-6)};
\node[draw, thick, fill=yellow!40, minimum height=5cm, minimum width=2mm, 
       inner sep=0pt, outer sep=0pt, anchor=south, rotate=26.5] at (3.1,-5) (a){};
\node[draw, thick, fill=yellow!40, minimum height=5cm, minimum width=2mm,
       inner sep=0pt, outer sep=0pt, anchor=south, rotate=-26.5] at (3.1,-5) (b){};
\draw[fill=black] (a.south) circle(0.11) node[below, outer sep=1mm]{A};
\draw[ultra thick] (a.center)--(b.center);
\end{tikzpicture}

\end{document}

在此处输入图片描述

答案3

你可以巧妙地做到这一点元帖子使用center运算符,返回代表给定路径pair中心的。bbox

倒置的 A 形

prologues := 3;
outputtemplate := "%j%c.eps";

beginfig(1);

pair apex; 
numeric u, alpha; 
path rectangle[]; 

u = 1cm;
apex = (3u, -5u); 
alpha = 53; % angle between the two legs

rectangle0 = unitsquare shifted 1/2 left xscaled 0.2u yscaled 5u;
rectangle1 = rectangle0 rotated +1/2 alpha shifted apex;
rectangle2 = rectangle0 rotated -1/2 alpha shifted apex;

rectangle3 = unitsquare shifted 1/2 down yscaled 0.2u 
                        xscaled length(center rectangle2 - center rectangle1)
                        shifted center rectangle1;

forsuffixes $=1,2,3:
  fill rectangle$ withcolor 0.4[white,red+green];
  draw rectangle$; 
endfor

fill fullcircle scaled .22u shifted apex;
label("A" infont "phvr8r",apex+8 down);

endfig;
end.

答案4

您可以对未旋转矩形的中心应用相同的旋转。换句话说,未旋转矩形的中心将是(3.1,-2.5)。因此,旋转矩形的中心为:

        ([rotate around={26.5:(3.1,-5)}]3.1,-2.5)

        ([rotate around={-26.5:(3.1,-5)}]3.1,-2.5)

连接这些点可得出:

在此处输入图片描述

我刚刚画了一条线,但是这应该可以让你根据这些坐标画出任何所需的矩形。

笔记:

  • 此解决方案的缺点之一是您需要指定两次旋转值。因此,使用\coordinates(根据 Harish Kumar 的解决方案)或\nodes(根据 Ignasi 的解决方案)更好。

代码:

\documentclass{article}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}
\draw[thick] (0,0) -- (6,0);
    \draw[thick,fill=yellow!40, rotate around={26.5:(3.1,-5)} ]  (3,0) rectangle (3.2,-5) node (a) {};
    \draw[thick,fill=yellow!40, rotate around={-26.5:(3.1,-5)}]  (3,0) rectangle (3.2,-5) node (b) {};
    \draw[fill=black] (3.1,-5) circle(0.11);
    \node at (3.1,-5.3) {A};
    \draw [red, ultra thick] 
        ([rotate around={26.5:(3.1,-5)}]3.1,-2.5) -- 
        ([rotate around={-26.5:(3.1,-5)}]3.1,-2.5);
\end{tikzpicture}
\end{document}

相关内容