2

I am trying to draw a single branch of hyperbola with tikz and I found in this forum a wonderful script here in this post (@DouglasMencken) : this post

\documentclass[tikz, margin=10]{standalone}

\usepackage{bm}

\usepackage{tikz}
\usetikzlibrary{shapes.geometric} % for shape=ellipse
\usetikzlibrary{calc}

\begin{document}

\def\tikzscale{0.8}
\begin{tikzpicture}[scale=\tikzscale]

\tikzset{
    elli/.style args={#1:#2and#3}{
        draw,
        shape=ellipse,
        rotate=#1,
        minimum width=2*#2,
        minimum height=2*#3,
        outer sep=0pt,
    }
}

%
% #1 optional parameters for \draw
% #2 angle of rotation in degrees
% #3 offset of center as (pointx, pointy) or (name-o-coordinate)
% #4 length of plus (semi)axis, that is axis which hyperbola crosses
% #5 length of minus (semi)axis
% #6 how much of hyperbola to draw in degrees, with 90 you’d reach infinity
%
\newcommand\tikzhyperbola[6][thick]{%
    \draw [#1, rotate around={#2: (0, 0)}, shift=#3]
        plot [variable = \t, samples=1000, domain=-#6:#6] ({#4 / cos( \t )}, {#5 * tan( \t )});

}

\def\angle{90}
\def\bigaxis{1.5cm}
\def\smallaxis{1.5cm}

\coordinate (center) at (0, 0);

\node [scale=\tikzscale, elli=\angle:\bigaxis and \smallaxis, line width = 1.2pt, color=black, dotted] at (center) (e) {};

\draw [-{stealth}, line width = 1.2pt, color = orange] ([shift={(\angle:-12)}] e.center) -- ([shift={(\angle:12)}] e.center) node [above right] {$\bm{a}_1$};
\draw [-{stealth}, line width = 1.2pt, color = orange] ([shift={(90+\angle:-8)}] e.center) -- ([shift={(90+\angle:8)}] e.center) node [above left]  {$\bm{a}_2$};

\tikzhyperbola[line width = 1.2pt, color=blue!80!black]{\angle}{(center)}{\bigaxis}{\smallaxis}{77}

\pgfmathsetmacro\axisratio{\smallaxis / \bigaxis}

% asymptotes
\def\lengthofasymptote{15}
\draw [color=black!40, line width = 0.4pt, rotate around={\angle + atan( \axisratio ): (center)}]
    ($ (-\lengthofasymptote, 0) + (center) $) -- ++(2*\lengthofasymptote, 0) ;
\draw [color=black!40, line width = 0.4pt, rotate around={\angle - atan( \axisratio ): (center)}]
    ($ (-\lengthofasymptote, 0) + (center) $) -- ++(2*\lengthofasymptote, 0) ;


\end{tikzpicture}

\end{document}

However, as you can see : I am only interested to plot the upper part of the graph which is only one branch : I don't get how to obtain this since I end up with a very large axis (I don't understand the mechanism of building the axis a_1 and a_2). For example if I want only the upper part of asymptote and put lengthasymptote = 0 as the first coordinate : the whole figure is shifted on the right.

Any help would be appreciated to understand this script in order to get the desired outcome as it seems very elegant and clean,

Thank you.

enter image description here

2
  • To identify relevant parts a quick way is to comment out temporarily and to compile. In best case you finally can delete some parts. In normal case you identified parts for modification. // Or you keep it as-is AND apply clipping, see the manual or search here.
    – MS-SPO
    Commented Apr 18 at 11:16
  • I did ! but for example there are some lines that I find excessively complicated or maybe very elaborated like this one : \draw [color=black!40, line width = 0.4pt, rotate around={\angle + atan( \axisratio ): (center)}] ($ (-\lengthofasymptote, 0) + (center) $) -- ++(2*\lengthofasymptote, 0) ;I still don't understand how the line is plotted using the rotate functionality...
    – Waxler
    Commented Apr 18 at 11:42

1 Answer 1

2

enter image description here

Since the function is sufficiently simple and in one variable, it would be better to use TikZ, to understand what you are doing and to be able to use on other occasions.

The hyperbola you want is described by the equation -x^2/a^2 +y^2/b^2 = 1. You need to solve for y and use plot.

The code

\documentclass[11pt, margin=8pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{math}
\begin{document}

\begin{tikzpicture}[evaluate={%
    \xend = 10;
    \a = 2;
    \b = 1.3;
  }, scale=.5]
  %% axes
  \begin{scope}[orange, ->, every node/.style={scale=.8}]
    \draw (-\xend -1, 0) -- (\xend +1, 0) node[below] {$x$};
    \draw (0, -1) -- (0, \xend*\b/\a +1) node[left] {$y$};
  \end{scope}

  %% asymptotes and circle
  \draw[gray, thin] (-\xend, \xend*\b/\a) -- (0, 0) -- (\xend, \xend*\b/\a);
  \draw[gray, dashed] (0, 0) circle (\b);
  
  %% branch of hyperbola
  \draw[blue, variable=\t, domain=-\xend:\xend, samples=50]
  plot (\t, {\b*pow(1 +(\t/\a)*(\t/\a), .5)});
\end{tikzpicture}
\end{document}

This site is temporarily in read-only mode and not accepting new answers.

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