如何在一条线上画圆并旋转它们

如何在一条线上画圆并旋转它们

关于以下 MWE 的两个问题:

\documentclass[12pt,a4paper]{scrartcl}  %%KOMA class
\setkomafont{sectioning}{\rmfamily\bfseries\boldmath}  %%

 \usepackage{tikz}
 \usetikzlibrary{rulercompass}
 \usetikzlibrary{intersections,quotes,angles}
 \usetikzlibrary{calc}

 \begin{document}
 \begin{tikzpicture}
 \draw [color=black!5] (0,0) grid (14,10);
 \draw (14,0) coordinate (a) node[right, below] {$x$}
       -- (0,0) coordinate (b) node[left] {(0,0)}
       -- (0,10) coordinate (c) node[left] {$y$};
 \draw [->, ultra thick] (0,2) coordinate (ad) node[left] {(0,2)}  -- (30:15cm) coordinate (dd)  node[above] {$l$};
 \draw (ad) -- (14,2)  coordinate (l);

 \path (ad) -- (dd) coordinate[pos=0.355](c1) coordinate[pos=0.692](c2);
 %circle A
 \draw [fill=red!15] (c1) circle [radius=2.365];
 %circle B
 \draw [fill=green!15] (c2) circle [radius=2.365];
 % centre  circles
 \draw (ad) -- (c1) node{$\bullet$} -- (c2) node {$\bullet$}--(dd)
 pic["$\alpha$", draw=red, <<-, angle eccentricity=1.1, angle radius=5cm]{angle=l--ad--dd}
 pic["$\alpha$", draw=red, <<-, angle eccentricity=1.1, angle radius=9.8cm]{angle=l--ad--dd};
 \end{tikzpicture}
 \end{document}
  1. 如何coordinate[pos=0.692]根据圆半径计算秒[radius=2.365]
  2. 我该如何绘制斜线的旋转l以使两个圆位于线上y=2正确的中心位置? 在此处输入图片描述

下面几乎解决了这个问题(需要清理的代码):

 \coordinate
 let
 \p1=(ad),\p2=(c1),\p3=(c2),\n1={veclen(\x2-\x1,\y2-\y1)},\n2={veclen(\x3-\x1,\y3-\y1)}
 in
 node (c1n) at (\n1,2) node (c2n) at (\n2,2);
 \draw [fill=red!25] (c1n) circle [radius=2.365];
 \draw [fill=green!25] (c2n) circle [radius=2.365];

 \draw
 let
 \p1=(ad),\p2=(c1),\p3=(c2),\n1={veclen(\x2-\x1,\y2-\y1)},\n2={veclen(\x3-\x1,\y3-\y1)}
 in
 (ad) -- (c1n) node{$\bullet$} -- (c2n) node{$\bullet$} {}--(l)
 pic["$\alpha$", draw=red, <<-, angle eccentricity=1.05, angle radius=\n1]{angle=l--ad--dd}
 pic["$\alpha$", draw=red, <<-, angle eccentricity=1.02, angle radius=\n2]{angle=l--ad--dd};
 \draw (ad) -- (14,2)  coordinate (l);

在此处输入图片描述

答案1

您可以使用库的功能calc来解决这两个问题。对于 1.,将第二个坐标定义为\coordinate (c2) at ($(c1)!2*2.365 cm!(dd)$);,即距离 两倍半径的点c1朝向dd

对于第二个,您可以使用语法计算到每个圆心的let距离,并将其用作,并在水平线上定义两个圆的中心点。ddangle radius

我还添加了制作圆圈的第二种可能方法,即使用nodes 和适当的anchor集合。

小提示:我不会\node {$\bullet$}在圆心使用,因为位置有点不对。我改用了一个填充的圆形节点,另一个选项是例如\fill (c1) circle[radius=2pt];

\documentclass[12pt,a4paper]{scrartcl}  %%KOMA class
\setkomafont{sectioning}{\rmfamily\bfseries\boldmath}  %% 

\usepackage{tikz}
\usetikzlibrary{rulercompass}
\usetikzlibrary{intersections,quotes,angles}
\usetikzlibrary{calc}
\tikzset{bullet/.style={circle,inner sep=0pt,minimum size=4pt,fill,draw}}
\begin{document}
\begin{tikzpicture}
 \draw [color=black!5] (0,0) grid (14,10);  
 \draw (14,0) coordinate (a) node[right, below] {$x$}
       -- (0,0) coordinate (b) node[left] {(0,0)} 
       -- (0,10) coordinate (c) node[left] {$y$};
 \draw [->, ultra thick] (0,2) coordinate (ad) node[left] {(0,2)}  -- (30:15cm) coordinate (dd)  node[above] {$l$};

 \path (ad) -- (dd) coordinate[pos=0.355](c1);
 \coordinate (c2) at ($(c1)!2*2.365 cm!(dd)$); 
 %circle A
 \draw [fill=red!15] (c1) circle [radius=2.365]; 
 %circle B
 \draw [fill=green!15] (c2) circle [radius=2.365]; 

 \path
 let
  \p1=(ad),\p2=(c1),\p3=(c2),\n1={veclen(\x2-\x1,\y2-\y1)},\n2={veclen(\x3-\x1,\y3-\y1)}
 in
  (ad) ++(\n1,0) coordinate (c1n)
  (ad) ++(\n2,0) coordinate (c2n);

 \draw [fill=red!15] (c1n) circle [radius=2.365]; 
 %circle B
 \draw [fill=green!15] (c2n) circle [radius=2.365]; 


 \draw (ad) -- (14,2)  coordinate (l);
 % draw angles
 \draw 
  let
  \p1=(ad),\p2=(c1),\p3=(c2),\n1={veclen(\x2-\x1,\y2-\y1)},\n2={veclen(\x3-\x1,\y3-\y1)}
   in
  (ad) -- (c1) node[bullet]{} -- (c2) node[bullet] {}--(dd)
   pic["$\alpha$", draw=red, <<-, angle eccentricity=1.05, angle radius=\n1]{angle=l--ad--dd}
   pic["$\alpha$", draw=red, <<-, angle eccentricity=1.02, angle radius=\n2]{angle=l--ad--dd};
\end{tikzpicture}

\begin{tikzpicture}[
  declare function={
   alpha=25; % angle
   R=2.365cm; % radius
   L=14cm; % length of ray
   circpos=0.5; % position of circle tangent along ray
  },
  mycirc/.style={
   circle,
   draw=black,
   thin,
   fill=#1,
   minimum size=R*2,
   outer sep=0pt,
   label={[bullet]center:}
  }
]

 \draw [color=black!5] (0,0) grid (L,10);  
 \draw (L,0) coordinate (a) node[right, below] {$x$}
       -- (0,0) coordinate (b) node[left] {(0,0)} 
       -- (0,10) coordinate (c) node[left] {$y$};

 \draw [->, ultra thick] (0,2) coordinate (ad) node[left] {(0,2)}  -- ++(alpha:L) coordinate (dd)
  node[above] {$l$}
  node[mycirc=red!15,anchor=alpha,pos=circpos] (c1) {}
  node[mycirc=green!15,anchor=alpha+180,pos=circpos] (c2) {};

% draw second set of circles
 \path (ad) -- ++(0:L)
  node[mycirc=red!15,anchor=0,pos=circpos] {}
  node[mycirc=green!15,anchor=180,pos=circpos]  {};

 \draw (ad) -- (L,2)  coordinate (l);

 \draw (c1.alpha+180) -- (c2.alpha);

 \draw 
  let
  \p1=(ad),\p2=(c1.center),\p3=(c2.center),\n1={veclen(\x2-\x1,\y2-\y1)},\n2={veclen(\x3-\x1,\y3-\y1)}
   in
   pic["$\alpha$", draw=red, <<-, angle eccentricity=1.05, angle radius=\n1]{angle=l--ad--dd}
   pic["$\alpha$", draw=red, <<-, angle eccentricity=1.02, angle radius=\n2]{angle=l--ad--dd};\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容