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.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am interested in drawing Cassini oval curve that has two foci A(-1,0) , B (1,0) and the other parameter is 3. I found this question but it won't suit my needs since asympote is not compiled by my LaTeX version and I have not worked with it before neither have I gotten to know it.

So, I am wondering if we can do it with tikz instead. In any comment in the linked question it says that someone would translate it to tikz but it does seem to be a link. Maybe I am wrong though and there is somewhere a solution using tikz exclusively.

Thank you in advance.

share|improve this question
    
Since you're familiar with TikZ, what have you tried so far? – cfr Mar 15 at 21:10
1  
math.uchicago.edu/~cstaats/Charles_Staats_III/… might be useful. – cfr Mar 15 at 21:13
    
@cfr Actually I only know basic staff of tikz. Draw something like this , well, I would have no idea where to begin. So, I have tried nothing. – Tolaso Mar 15 at 21:33
    
If you know Tikz, you can translate my answer (22.5 Plotting a Function etc...). tkz-fct is based on Tikz and uses gnuplot so you need to install gnuplot but for complex function I think it's "indispensable". – Alain Matthes Mar 15 at 21:36
up vote 6 down vote accepted

You need to determine a good domain and some coefficients. Update for the color

\documentclass[a4paper]{article}
\usepackage{tkz-fct}

\begin{document}
\begin{tikzpicture}[scale=.75]
   \tkzInit [xmin=-1,xmax=1,
             ymin=-1,ymax=1,
             xstep=.2,ystep=.2]
  \foreach \i in {4,3.8,...,1.2}    {%
  \pgfmathsetmacro{\n}{8*\i}
  \tkzFctPolar[domain=-pi:pi,fill=green!\n!white]{%
  sqrt(cos(2*t)+sqrt(\i-sin(2*t)*sin(2*t)))}  
  \tkzFctPolar[domain=-pi:pi,fill=green!\n!white]{%
  sqrt(cos(2*t)+sqrt(\i+sin(2*t)*sin(2*t)))}
  }
\end{tikzpicture}
\end{document}

enter image description here

share|improve this answer
    
Thanks Alain. One question. How do we fill that , e.g with a color say light green? – Tolaso Mar 15 at 21:34
    
@Tolaso No problem I updated my answer. you need to use the loop with decreasing numbers – Alain Matthes Mar 15 at 21:45
    
engine ? for me lualatex. viewer ? when you compile you get a result ? you have gnuplot installed ? – Alain Matthes Mar 15 at 22:36
    
Hang on a minute... I have to run it with LuaLaTeX? I have gnuplot installed. Engine is PDFLaTeX... When I compile I do not get a result , just a blank page. P.S: I accepted your answer as it is close to what I want to do. – Tolaso Mar 15 at 23:43
    
OK, solved.. !! I was doing something wrong. Thanks – Tolaso Mar 15 at 23:59

Polar coordinates seems a good way to draw the curve as plot with the angle as parameter. The radius can be calculated with the second equation of the Wikipedia article.

\documentclass{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[
  x=2cm,
  y=2cm,
]
  \def\samples{180}
  \def\c{1}
  \pgfmathsetmacro\cc{\c*\c}
  \pgfmathsetmacro\cccc{\cc*\cc}
  \def\a{1.01}
  \foreach\a in {1.001, 1.01, 1.05, 1.1, 1.3, 1.6, 2, 2.5, 3} {
    \pgfmathsetmacro\aa{\a*\a}
    \pgfmathsetmacro\aaaa{\aa*\aa}
    \pgfmathsetmacro\aaaaMcccc{\aaaa - \cccc}
    \draw
      plot[
        variable=\t,
        domain=0:360-1/\samples,
        samples=\samples,
        smooth cycle,
      ]
      (\t:{\cc*sqrt(\cc*cos(2*\t) + sqrt(\cccc*cos(2*\t)*cos(2*\t) + \aaaaMcccc))})
    ;
  }
  \path plot[mark=x] coordinates { (-\c, 0) (\c, 0) };
\end{tikzpicture}
\end{document}

Result

The angle is \t, the foci can be configured with \c. The example shows the curves for different values of \a.

Lemniscate

In this case \a equals \c, this simplifies the formula. Since the angles are now non-continuous, the curve is drawn in two parts, first the right, then the left. Also filling is shown.

\documentclass{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[
  x=2cm,
  y=2cm,
]
  \def\samples{100}
  \def\c{1}
  \pgfmathsetmacro\cc{\c*\c}
  \pgfmathsetmacro\cccc{\cc*\cc}
  \def\a{1.01}
  \draw[fill=green!50!white]
    (0, 0) --
    plot[
      variable=\t,
      domain=-45+1/\samples:45-1/\samples,
      samples=\samples,
      smooth,
    ]
    (\t:{\cc*sqrt(\cc*cos(2*\t) + \cc*cos(2*\t))})
    -- cycle
  ;
  \draw[fill=green!50!white]
    (0, 0) --
    plot[
      variable=\t,
      domain=180-45+1/\samples:180+45-1/\samples,
      samples=\samples,
      smooth,
    ]
    (\t:{\cc*sqrt(\cc*cos(2*\t) + \cc*cos(2*\t))})
    -- cycle
  ;
  \path plot[mark=x] coordinates { (-\c, 0) (\c, 0) };
\end{tikzpicture}
\end{document}

Result

share|improve this answer
    
Thanks @Heiko . But this does not compile. I get an error of "Package PGF Math Error: I cannot calculate the square-root of the negative nu" – Tolaso Mar 15 at 21:49
    
Or you can use tikz with gnuplot – Alain Matthes Mar 15 at 21:50
    
@Tolaso \a must be greater than \c. The other cases with smaller \a are not implemented, since the question says that the other parameter is 3, three times greater than 1. – Heiko Oberdiek Mar 15 at 21:58

Run with xelatex. It uses the implicit defined function and the variables \rA and \rC.

\documentclass[a4paper]{article}
\usepackage{pst-func}

\begin{document}
\psset{unit=2}
\begin{pspicture}(-2.5,-2.5)(2.5,2.5)
\psaxes[labels=none,Dx=0.5,Dy=0.5,ticksize=-3pt 3pt]{->}(0,0)(-2,-2)(2,2)[$x$,-90][$y$,0]
\def\rC{1} 
\pgfforeach \rA in {0,0.2,...,1.6}{%
\psplotImp[linewidth=1pt,algebraic,linecolor=blue!60]%
  (-3,-3)(3,3){(x^2+y^2)^2-2*\rC^2*(x^2-y^2)-\rA^4+\rC^4}}
\end{pspicture}

\begin{pspicture}(-2.5,-2.5)(2.5,2.5)
\psaxes[labels=none,Dx=0.5,Dy=0.5,ticksize=-3pt 3pt]{->}(0,0)(-2,-2)(2,2)[$x$,-90][$y$,0]
\def\rC{2} 
\pgfforeach \rA in {0,0.2,...,2.4}{%
    \psplotImp[linewidth=1pt,algebraic,linecolor=red!60]%
    (-3,-3)(3,3){(x^2+y^2)^2-2*\rC^2*(x^2-y^2)-\rA^4+\rC^4}}
\end{pspicture}
\end{document}

enter image description here

share|improve this answer
    
Very nice Herbert.. Nice of pstricks... ! – Tolaso Mar 15 at 22:12

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.