10

Two questions about the following 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. How do I calculate the second coordinate[pos=0.692] in terms of the circle radius [radius=2.365]?
  2. How do I draw the rotation of the oblique line l as to center the two circles on the y=2 line at the correct position? enter image description here

The following almost fixes it (code to be cleaned):

 \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);

Enter image description here

  • 2
    Probably I'm slow/ignorant, but I don't understand what you want to do in point 2. Can you try to explain more thoroughly? – Torbjørn T. May 23 '17 at 10:37
  • 1
    @Torbjørn T. pls. see new picture (which I draw by guessing the radius values of the two pics, which is not good). I wish to know if I may instruct tikz to calculate how to draw the two circles after rotation of line l from its present position to y=2. Am i clear? – mario May 23 '17 at 10:49
12

You can use the features of the calc library for both problems. For 1., define the second coordinate as \coordinate (c2) at ($(c1)!2*2.365 cm!(dd)$);, i.e. the point that is twice the radius away from c1, towards dd.

For the second you can use the let syntax to calculate the distance from dd to each of the circle centers, and use that as the angle radius, and to define the center points of the two circles on the horizontal line.

I also added a second possible method for making the circles, by using nodes with an appropriate anchor set.

Small note: I wouldn't use \node {$\bullet$} in the circle centers, as that is positioned a bit wrong. I used a filled, circular node instead, another option would be e.g. \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}

enter image description here

| improve this answer | |
  • Not sure if this fully answered your question .. – Torbjørn T. May 23 '17 at 10:57
  • Op only asks how to set the center of the rightmost green circle, relatively to the left pink one, but it seems they actually want both circles to be tangent in the middle of the (ad)--(dd) ray. In that case, both (c1) and (c2) should be computed in the same way relatively to the middle. – marsupilam May 23 '17 at 11:01
  • @marsupilam Maybe you're right. mario: is that correct, should the circles meet at the exact midpoint of the line l? – Torbjørn T. May 23 '17 at 11:06
  • I am checking. Also, how do convert to .png: I use convert -density 300 0041.pdf -quality 100 0041a.png, but your picture looks better, why? – mario May 23 '17 at 11:06
  • @mario I just took a screenshot of the PDF .. – Torbjørn T. May 23 '17 at 11:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.