Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

How can I make a convex lens with TikZ?

I tried using arcs but this doesn't look right.

\documentclass[tikz]{standalone}
\begin{document}
\begin{tikzpicture}
  \pgfmathsetmacro{\xr}{0.35}
  \pgfmathsetmacro{\yr}{2}

  \draw (0, 0) coordinate (O) arc[x radius = \xr cm, y radius = \yr cm,
  start angle = 90, end angle = 270];
  \draw (O) arc[x radius = \xr cm, y radius = \yr cm,
  start angle = 90, end angle = -90];
\end{tikzpicture}
\end{document}

I would like the arcs to meet at a sharp corner not rounded.

enter image description here

share|improve this question
    
Slightly related question: tex.stackexchange.com/questions/33460/tikz-library-for-optics (Edit: It doesn't exactly answer your question, I just added it for reference.) –  Torbjørn T. May 27 at 19:54
    
Depending on where you're heading, you might want to have a look at pst-optexp. –  Christoph May 28 at 12:34

4 Answers 4

up vote 7 down vote accepted

Here is one suggestion:

\documentclass[tikz]{standalone}
\begin{document}
\begin{tikzpicture}
  \pgfmathsetmacro{\lensRadius}{2}
  \pgfmathsetmacro{\lensHeight}{1}
  \pgfmathsetmacro{\startAngle}{asin(\lensHeight/\lensRadius)}

  \draw (0,\lensHeight) arc[start angle=180-\startAngle,delta angle=2*\startAngle,radius=\lensRadius];
  \draw (0,\lensHeight) arc[start angle=\startAngle,delta angle=-2*\startAngle,radius=\lensRadius];
\end{tikzpicture}
\end{document}

enter image description here

Slightly modified, for filling, and better line ends:

\documentclass[tikz,border=5mm]{standalone}
\begin{document}
\begin{tikzpicture}
  \pgfmathsetmacro{\lensRadius}{2}
  \pgfmathsetmacro{\lensHeight}{1}
  \pgfmathsetmacro{\startAngle}{asin(\lensHeight/\lensRadius)}

  \draw [fill=blue!15]  (0,\lensHeight)
  arc[start angle=180-\startAngle,delta angle=2*\startAngle,radius=\lensRadius]
  arc[start angle=-\startAngle,delta angle=2*\startAngle,radius=\lensRadius]
   -- cycle; % to get a better line end
\end{tikzpicture}
\end{document}

enter image description here

share|improve this answer
    
What is/does the delta angle option do? –  dustin May 27 at 19:49
    
@dustin It is the difference between the start and the end angle. So it creates an arc that spans delta angle degrees. –  Torbjørn T. May 27 at 19:51
    
Is the lack of the closing ) in asin(… on purpose? –  Henri Menke May 27 at 21:42
    
@HenriMenke No, that is what you'd call a mistake. Thanks. Still worked though ... –  Torbjørn T. May 27 at 21:51

enter image description here

\documentclass[tikz]{standalone}
\begin{document}

\begin{tikzpicture}

\draw[line join=round,fill=blue!15] (0,0) arc (-30:30:2 and 3) arc (150:210:2 and 3) ;

\end{tikzpicture}
\end{document}  
share|improve this answer

From my previous TiKz studying:

\documentclass[tikz]{standalone}
\begin{document}
\begin{tikzpicture}
  \draw[fill=orange]
  ([shift={(-40:1cm)}]0,0) arc (-40:40:1cm);
   \draw[fill=orange,rotate=180]
  ([shift={(-40:1cm)}]-1.535,0) arc (-40:40:1cm);
\end{tikzpicture}
\end{document}

enter image description here

share|improve this answer

Just draw two lines:

\documentclass[tikz]{standalone}
\begin{document}

\begin{tikzpicture}
\draw[fill=blue!15] (0,2) to[in=130,out=230] (0,-2) to[in=-50,out=50] (0,2) -- cycle;

\end{tikzpicture}
\end{document}

enter image description here

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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