可以在 TikZ 中用参数绘制双曲线吗?

可以在 TikZ 中用参数绘制双曲线吗?

我正在使用 TikZ 绘制一些圆锥曲线图。有一个内置的椭圆命令(半轴作为两个参数)和一个基本的抛物线命令(带有垂直轴,但可以旋转),但要绘制双曲线,我必须用样条曲线来伪造它并从外部计算控制点。我不想绘制像素序列,我更喜欢可以轻松修改的参数。在 TikZ 中,是否有一种仅从半轴和中心位置绘制双曲线的快捷方式?

我对样条近似并不感到不满,它们对于心形线等来说效果很好,但是有没有更简单的方法用 TikZ 获得双曲线?

答案1

请参阅pgf手册中的第 19.5 和 19.6 节。您可以绘制由简单参数方程给出的曲线,例如

 \draw[scale=0.5,domain=-3.141:3.141,smooth,variable=\t] plot ({\t*sin(\t r)},{\t*cos(\t r)});

因此,如果您能找到双曲线的参数方程,您就应该能够绘制它。

答案2

来,拿这个双曲线绘图样本来玩玩。机械是

%
% #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 )});
    \draw [#1, rotate around={#2: (0, 0)}, shift=#3]
        plot [variable = \t, samples=1000, domain=-#6:#6] ({-#4 / cos( \t )}, {#5 * tan( \t )});
}

样品图片

\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 )});
    \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{33}
\def\bigaxis{3.2cm}
\def\smallaxis{1.5cm}

\draw [color=blue, line width = 0.4pt, dotted] (-7, 0) -- (7, 0) node [right] {$x_{1}$};
\draw [color=blue, line width = 0.4pt, dotted] (0, -5) -- (0, 5) node [above] {$x_{2}$};

\coordinate (center) at (-6, 2);

\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) ;

\tikzhyperbola[line width = 1.2pt, color=red!80!black]{90+\angle}{(center)}{\smallaxis}{\bigaxis}{76}

\end{tikzpicture}

\end{document}

答案3

这应该可以解决问题

\draw plot[variable=\t,samples=1000,domain=-35:35] ({sec(\t)},{tan(\t)});

相关内容