2

I'm trying to write Tikz that will draw lines on a circle at regular intervals (in order to slice it) and have used this code:

\begin{tikzpicture} \draw (0,0) circle(2); \draw plot[domain=pi:2*pi] ({2*cos(\x r)},{.4*sin(\x r)}); \draw[dashed] plot[domain=0:pi] ({2*cos(\x r)},{.4*sin(\x r)}); \foreach \y in {-2, -1.8, ..., 2}{ \draw (sqrt{4-\y*\y},\y) -- (-1 * sqrt{4-\y*\y},\y); } \end{tikzpicture} 

however this code produces: the incorrect result

which as you can guess, isn't the result I'm looking for, where did I go wrong?

2
  • 1
    write \draw ({sqrt(4-\y*\y)},\y) -- ({-1 * sqrt(4-\y*\y)},\y); instead of \draw (sqrt{4-\y*\y},\y) -- (-1 * sqrt{4-\y*\y},\y); Commented Feb 22 at 23:36
  • 1
    The sqrt uses parentheses for its arguments. The entire coordinate component must be enclosed in curly braces, since your logic used parentheses. Commented Feb 22 at 23:37

1 Answer 1

2

As Jasper pointed out in their comment, your syntax for calculating the coordinates of the slice endpoints is wrong. Try it this way:

\begin{tikzpicture}[ declare function={f(\x) = sqrt(4-(\x)^2);} ] \draw (0,0) circle(2); \draw plot[domain=pi:2*pi] ({2*cos(\x r)},{.4*sin(\x r)}); \draw[dashed] plot[domain=0:pi] ({2*cos(\x r)},{.4*sin(\x r)}); \foreach \y in {-2, -1.8, ..., 2}{ \draw ({-f(\y)},\y) -- ({f(\y)},\y); } \end{tikzpicture} 

I like the declare function key for this because you can write out the formula once and refer to it by name.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.