我试图将一个矩形放在一个具有一定半径的假想圆的顶部,该圆的中心位于另一个矩形的中间。到目前为止,我尝试过以下方法
\documentclass{article}
\usepackage{kerkis}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
% Incident Beam
\draw[->, thick] (0,0) -- (2,0);
% Target : Boron + Au --- The center of the imaginary circle is in the center of these rectangles
\draw[gray!30,fill=gray!30] (6,1) rectangle (6.5,-1);
\draw[gray!70,fill=gray!70] (6.5,1) rectangle (8.5,-1);
% Scattering Chamber - The imaginary circle
%\draw[thick,red,->,dashed] ([shift=(-120:5cm)]7.25,0) arc (0:100:-1cm);
%\draw[dashed, gray!50] (7.25,0) circle (7cm);
% Telescopes --- I want to place this rectangle on 170 degrees on top of the imaginary circle
\draw[black!70, fill=black!70, rotate=30] (2,-2) rectangle (2.5, -2.5);
\end{tikzpicture}
\end{document}
我的输出是
如何将这个黑色矩形以一定角度放置在虚线圆的上方?
答案1
如果想象圆的中心在(7.25,0)
,并且圆的半径为 7cm,则可以在 处插入一个旋转的矩形节点(7.25,0)+(170:7)
:
\path(7.25,0)+(170:7)
node[
fill=black!70,
minimum width=.5cm,minimum height=1cm,% rectangle
rotate=80 % 170°-90°=80°
]{};
代码:
\documentclass[margin=5mm]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
% Incident Beam
\draw[->, thick] (0,0) -- (2,0);
% Target : Boron + Au --- The center of the imaginary circle is in the center of these rectangles
\draw[gray!30,fill=gray!30] (6,1) rectangle (6.5,-1);
\draw[gray!70,fill=gray!70] (6.5,1) rectangle (8.5,-1);
% Scattering Chamber - The imaginary circle
%\draw[thick,red,->,dashed] ([shift=(-120:5cm)]7.25,0) arc (0:100:-1cm);
\draw[dashed, red] (7.25,0)coordinate(M) circle [radius=7cm];
% Telescopes --- I want to place this rectangle on 170 degrees on top of the imaginary circle
\path(7.25,0)+(170:7)
node[fill=black!70,
minimum width=.5cm,minimum height=1cm,% rectangle
rotate=80 % 170°-90°=80°
]{};
\end{tikzpicture}
\end{document}
答案2
您还可以使用节点,
\documentclass[tikz]{standalone}
\begin{document}
\begin{tikzpicture}
\node[draw,dotted,minimum size=3cm,circle] (a) {};
\node[fill,minimum size=2mm,rotate=55,inner sep=0] at (a.140) {};
\end{tikzpicture}
\end{document}
答案3
另一个想法:对填充的正方形使用倾斜节点。这样,您不必指定旋转该正方形的角度,它将自动计算为与圆的半径对齐:
\begin{tikzpicture}
\tikzset{
my square/.style={
fill=orange!70,
minimum size=2mm,
pos=1,
sloped
}
}
\draw [dotted] (0,0) circle(1.5cm);
\foreach \angle in {0,30,...,360}
\foreach \distance in {0.9,1.2,1.5}
\path (0,0) -- (\angle:\distance)
node[my square] {};
\end{tikzpicture}
更新
回答评论中的附加问题,可以绘制一个矩形,给出节点的最小宽度和高度。但是,将宽度保留为具有默认值的参数可能很有用:
\begin{tikzpicture}
\tikzset{
my rectangle/.style={
fill=orange!70,
minimum width=#1, % The width is a parameter
minimum height=2mm,
pos=1,
sloped
},
my rectangle/.default = 4mm, % Width when not specified
}
\draw [dotted] (0,0) circle(1.5cm);
% Some rectangles with default width
\foreach \angle in {0,30,...,330}
\path (0,0) -- (\angle:1.5) node[my rectangle] {};
% Other rectangles with given width (and different color)
\foreach \angle in {0,90,...,330}
\path (0,0) -- (\angle:1.5) node[my rectangle=7mm, red] {};
\end{tikzpicture}