![旋转矩形中点之间的矩形](https://linux22.com/image/301495/%E6%97%8B%E8%BD%AC%E7%9F%A9%E5%BD%A2%E4%B8%AD%E7%82%B9%E4%B9%8B%E9%97%B4%E7%9A%84%E7%9F%A9%E5%BD%A2.png)
我需要在两个旋转的矩形的中点之间画一个矩形(如下所示)。
我该怎么做呢?
我的当前代码显示如下。
当前代码
\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
只需定义两个coordinates
a 和 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
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}