11

I want to draw something like this using TikZ:

curve example

I can probably make the curve using controls but that wouldn't allow me to draw the points on it.

3
  • Just for the maintenance purposes: Is it OK if we replace the image with the result of the answer? I can't tell since the image does not exist anymore.
    – percusse
    Nov 15, 2011 at 21:59
  • @GuanHao: Stackexchange has a special subdomain for imgur.com (stack.imgur.com), where images usually never expire, what they will do otherwise after some time. For uploading them to that special subdmn one must use the according button for image including or the keyboard shortcut Ctrl+G inside the edit function. (Why the original image, that was on stack.imgur.com, not is accessible anymore, I don’t know.)
    – Speravir
    May 4, 2012 at 20:37
  • Probably MetaPost is a better tool for that.
    – mbork
    May 4, 2012 at 21:08

2 Answers 2

11

You could use the intersections library. Here is a modified version of one of the examples from the pgfmanual (TikZ 2.0). It's reasonable close to your figure and you should be able to modify it.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{intersections}
\begin{document}
\begin{tikzpicture}
\clip (-2,-2) rectangle (2,2);
\draw [name path=curve] (-2,1) .. controls (8,1) and (-8,-1) .. (2,-1);
\path[name path=line 1] (0,-2) -- (0,2)  (-1,-2) -- (-1,2) (1,-2) -- (1,2);
\draw [name intersections={of=curve and line 1, name=i}] 
  (i-6) -- (i-7) (i-5) -- (i-8);
\draw [name intersections={of=curve and line 1, name=i},name path=line 2]
  (i-5) --(i-3) -- (i-7) (i-6) -- (i-2) -- (i-8); 

\fill [name intersections={of=curve and line 1, name=i}][blue, opacity=0.5]
\foreach \s in {1,2,3,5,6,7,8}{(i-\s) circle (2pt)};

\fill [name intersections={of=curve and line 2, name=i}][blue, opacity=0.5]
\foreach \s in {5,7}{(i-\s) circle (2pt) node {\footnotesize\s}};
\end{tikzpicture}
\end{document}

This might be better?

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{intersections}

\begin{document}
\begin{tikzpicture}

\path[name path=circle] 
  (0,0) circle (2cm);

\path[name path=cross] 
  (-2,-2) -- (2,2) 
  (-2,2) -- (2,-2) 
  (0,2) -- (0,-2);

\draw [% 
  name intersections={of=circle and cross, name=i},
  name path=line
] 
  (i-1) -- (i-5) -- (i-3) 
  (i-4) -- (i-2) -- (i-6) 
  (i-1) -- (i-4) 
  (i-3) -- (i-6);

\fill [% 
  name intersections={of=line and line, name=i}
] [blue, opacity=0.5]
  \foreach \s in {1,2,3,6,8,10,11,21,25}{(i-\s) circle (2pt)};

\draw [%
  name intersections={of=line and line, name=i}
]
  (i-8) ++(-0.5,0) -- (i-8) 
    to[out=45,in=180]  (i-10) 
    to[out=0,in=135]   (i-3)
        to[out=-45,in=0]   (i-2)
    to (i-21) to (i-6) 
    to[out=180,in=135] (i-11)
    to[out=-45,in=180] (i-1)
    to[out=0,in=225]   (i-25) 
    --++(0.5,0);

\end{tikzpicture}
\end{document}
4

You can draw the points (and give each point a name for convenience when drawing the curve) and the straight lines first.

When drawing the curve check out the in and out options which control the angles. Search "in=" or "out=" in the manual and you will get tons of examples.

You must log in to answer this question.