7

Below is the minimal example of my code. I would like the dotted line to stay within the circle rather than overshooting it like it currently is but I am not able to figure out how this can be done.

\documentclass[paper=a4, fontsize=12pt]{scrartcl} 

\usepackage[T1]{fontenc} 
\usepackage{amsmath,amsfonts,amsthm} % Maths  
\usepackage{graphicx} 
\usepackage{float}

\usepackage{tikz}
\usetikzlibrary{arrows,%
                plotmarks}
\begin{document}

 \begin{figure}[H]
 \centering
   \begin{tikzpicture}
    % Axis
    \draw[thick,->,black] (-3,0)--(3,0) node[below] {$k_x$}; % x axis
    \draw[thick,->,black] (0,-3)--(0,3) node[left] {$k_y$}; % y axis
    \draw[black,thick] (0,0) circle (2.5cm);
    \draw[ultra thick,blue,dashed] (0,0) -- (3,3);

   \end{tikzpicture}
\end{figure}
\end{document}

circle

I would also like to place equidistant dots as the background to my circle. I have no idea where to start! Can anyone help?

3
  • 2
    Your dashed line should have length the radius of your circle (2.5 cm), so it should go to the point (2.5/sqrt(2), 2.5/sqrt(2)), not to (3,3). Someone else will have to help you with the background. Commented Mar 8, 2013 at 1:24
  • @EthanBolker Oh so that is what that meant. I put to 1.77,1.77 and it worked. I do not know if it is possible to use sqrt in there, but it looks good now. How about the equidistant dots?
    – Magpie
    Commented Mar 8, 2013 at 1:39
  • You can use patterns to fill your circle. With \draw[black,thick,pattern=dots,pattern color=red] (0,0) circle (2.5cm); you will get a circle filled with red equidistant dots. You must also load patterns library to use them.
    – Ignasi
    Commented Mar 8, 2013 at 8:19

2 Answers 2

9

Explanation

Use a polar coordinate instead. Since (3,3) makes an angle of 45 degrees with the positive part of the x-axis, and you have used 2.5 cm as your radius, you can specify the coordinate as (45:2.5cm), which implicitly means (canvas polar cs:angle=45,radius=2.5cm). You can see some more explanations in the pgf manual, page 125 in version 2.10.

Code

%\documentclass[paper=a4, fontsize=12pt]{scrartcl} 
\documentclass[preview,border=5]{standalone}

\usepackage[T1]{fontenc} 
\usepackage{amsmath,amsfonts,amsthm} % Maths  
\usepackage{graphicx} 
\usepackage{float}

\usepackage{tikz}
\usetikzlibrary{arrows,%
                plotmarks}
\begin{document}

 \begin{figure}[H]
 \centering
   \begin{tikzpicture}
    % Axis
    \draw[thick,->,black] (-3,0)--(3,0) node[below] {$k_x$}; % x axis
    \draw[thick,->,black] (0,-3)--(0,3) node[left] {$k_y$}; % y axis
    \draw[black,thick] (0,0) circle (2.5cm);
    \draw[ultra thick,blue,dashed=on 2pt off 3pt] (0,0) -- (45:2.5cm); % Use the polar coordinate (<angle>:<length>) instead

   \end{tikzpicture}
\end{figure}
\end{document}

Output

enter image description here

Edit

I didn't see your second concern. Although I should advise you to limit your questions in one post in the future. See the modified code below. Some explanations:

  • \pgflinewidth takes the value of line width key which is given here the value of 0.5pt.
  • I have added fill=white to the nodes of your axis labels to distinguish them from the dotted lines and added some distance in order to not cover the arrows.

%\documentclass[paper=a4, fontsize=12pt]{scrartcl} 
\documentclass[preview,border=5]{standalone}

\usepackage[T1]{fontenc} 
\usepackage{amsmath,amsfonts,amsthm} % Maths  
\usepackage{graphicx} 
\usepackage{float}

\usepackage{tikz}
\usetikzlibrary{arrows,%
                plotmarks,patterns}
\begin{document}

 \begin{figure}[H]
 \centering
   \begin{tikzpicture}
   \draw [line width=0.5pt, line cap=round, dash pattern=on 0pt off 2\pgflinewidth] (-3,-3) grid (3,3);
    % Axis
    \draw[thick,->,black] (-3,0)--(3,0) node[below=1.75pt, fill=white] {$k_x$}; % x axis
    \draw[thick,->,black] (0,-3)--(0,3) node[left=1.75pt, fill=white] {$k_y$}; % y axis
    \draw[black,thick] (0,0) circle (2.5cm);
    \draw[ultra thick,blue,dashed=on 2pt off 3pt] (0,0) -- (canvas polar cs:angle=45,radius=2.5cm);
   \end{tikzpicture}
\end{figure}
\end{document}

Reference

See Dotted lines in TikZ with round dots for the different approaches for producing the dotted lines in tikz.

enter image description here

1
  • hey thanks that was nicer than the way I fixed it. Do you have any ideas on the second part of the problem?
    – Magpie
    Commented Mar 8, 2013 at 3:56
8

Another option, in addition to using polar coordinates or calculating the coordinates of the terminal point of the dashed line using trigonometry would be use of clipping. It is probably an overkill in this case, but it could be useful for more complicated situations:

\documentclass[paper=a4, fontsize=12pt]{scrartcl} 

\usepackage[T1]{fontenc} 
\usepackage{amsmath,amsfonts,amsthm} % Maths  
\usepackage{graphicx} 
\usepackage{float}

\usepackage{tikz}
\usetikzlibrary{arrows,%
                plotmarks}
\begin{document}

 \begin{figure}[H]
 \centering
   \begin{tikzpicture}
    % Axis
    \draw[thick,->,black] (-3,0)--(3,0) node[below] {$k_x$}; % x axis
    \draw[thick,->,black] (0,-3)--(0,3) node[left] {$k_y$}; % y axis
    \draw[black,thick] (0,0) circle (2.5cm);
    \begin{scope}
       \draw[clip] (0,0) circle (2.5cm);
       \draw[ultra thick,blue,dashed] (0,0) -- (3,3);
    \end{scope}
   \end{tikzpicture}
\end{figure}
\end{document}

Notice that the circle is drawn twice, the second time inside the scope environment with the clip option. That will caused everything in this environment to be clipped to the inside of the circle.

1
  • 1
    To avoid to draw twice the circle, use \clip... or \path[clip]... instead of \draw[clip]. Commented Mar 8, 2013 at 8:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .