100 如何绘制坐标轴中倾斜的双曲线及其渐近线?

发布于 2026-07-30 16:36:03

希望绘制如下的图:

image.png

希望通过对比找到「最佳实践」,欢迎尽可能多的方法。

由于我自己会答,这里不给出MWE。

如果您使用了AI,希望您能同时提供「模型名称」、「提示词」、「使用心得/推荐度」等附加信息。

查看更多

关注者
0
被浏览
95
3 个回答
Sagittarius Rover
Sagittarius Rover 11小时前
这家伙很懒,什么也没写!

基于tkz-elements的一个回答,优点是便于控制双曲线的各个指标,直接获得渐近线:

% lualatex needed
\documentclass[border=1cm]{standalone}
% \usepackage[times]{fontsetup}
\usepackage[mini]{tkz-euclide}
\usepackage{tkz-elements}
\begin{document}
\directlua{
    z.p0 = point(-2, 2)
    local a, b = 2, 1
    L.axis = line(z.p0, z.p0 + point(2, 2))
    local c = math.sqrt(a * a + b * b)
    z.F1 = L.axis:report(c)
    z.F2 = L.axis:report(-c)
    CO.H = conic(HY_bifocal(z.F1, z.F2, a))
    z.V1 = CO.H.vertex
    z.V2 = z.V1:symmetry(z.p0)
    PA.H1 = CO.H:points(-10, 10, 100)
    PA.H2 = CO.H:points(-10, 10, 100, "swap")
    L.A1, L.A2 = CO.H:asymptotes()
    z.asym1u, z.asym1v = L.A1:get()
    z.asym2u, z.asym2v = L.A2:get()
    z.xpos = point(2, 6)
    z.xneg = point(-6, -2)
    z.ypos = point(-6, 6)
    z.yneg = point(3, -3)
}
    \begin{tikzpicture}[myarrow/.style={-latex,thick}]
    \tkzGetNodes
    \path[use as bounding box] (-6,-3) rectangle (3,6);
    \draw[myarrow] (-7,0) -- (4,0);
    \draw[myarrow] (0,-4) -- (0,6);
    \draw[myarrow] (xneg) -- (xpos);
    \draw[myarrow] (yneg) -- (ypos);
    \tkzDrawCoordinates[smooth,magenta](PA.H1)
    \tkzDrawCoordinates[smooth,magenta](PA.H2)
    \tkzDrawSegments[dashed](V1,V2)
    \tkzDrawLines[dashed,cyan,add=15 and 15](asym1u,asym1v asym2u,asym2v)
    \end{tikzpicture}
\end{document}

image.png

Absinthe
Absinthe 11小时前
这家伙很懒,什么也没写!

asymptote 方案

基于 asymptotegeometry 模块。

基本想法

借助 geometry 模块,可以较为轻松的绘制出双曲线及其渐近线的图像,剩下处理坐标轴及其变换的绘制。
考虑使用坐标轴(使用起点和方向确定)与边界框的交点作为坐标轴的起点和终点,并完成标注即可。

image.png

最终效果

如下:
image.png

绘图代码

最终代码如下。有待优化的地方:如下代码在设置双曲线的变换以及坐标轴的变换时重复了一次设置。

settings.outformat="pdf"; unitsize(1cm);
import geometry;
void draw(
    path bbox, coordsys R,
    Label lo = Label("$O$", align=SW),
    Label li = Label("$x$", relative(1), align=S),
    Label lj = Label("$y$", relative(1), align=W),
    arrowbar arrow = Arrow(TeXHead))
{
    pair pO = point(R, (0,0)), pi = point(R, (1,0)), pj = point(R, (0,1));
    pair di = unit(pi - pO), dj = unit(pj - pO);
    real extent = length(max(bbox) - min(bbox)) * 2;

    pair xp = intersectionpoint(pO -- (pO + extent * di), bbox);
    pair xn = intersectionpoint(pO -- (pO - extent * di), bbox);
    pair yp = intersectionpoint(pO -- (pO + extent * dj), bbox);
    pair yn = intersectionpoint(pO -- (pO - extent * dj), bbox);

    draw(xn -- xp, arrow); draw(yn -- yp, arrow);
    label(lo, pO, lo.align.dir);
    label(li, xp, li.align.dir);
    label(lj, yp, lj.align.dir);
}
/*======== 定义(Define) =========*/
path bbox = box((-6,-3),(3,6));
coordsys R = cartesiansystem(O=(-2,2), i=(2,2), j=(-2,2));
hyperbola hyp = hyperbola(C=(-2,2), a=2, b=1, angle=45);
/*======== 绘制(Draw) =========*/
draw(bbox,invisible); draw(bbox,defaultcoordsys);
draw(bbox, R, lo = Label("$O'$", align=2dir(-80)), 
              li=Label("$x'$", align=E), lj=Label("$y'$", align=W));
draw(hyp); draw(hyp.A1 ^^ hyp.A2, dashed);
Sagittarius Rover
Sagittarius Rover 2小时前
这家伙很懒,什么也没写!

也可以考虑使用luadraw,提供了g:Shiftg:Rotate等方便的方法:

\documentclass{standalone}
\usepackage{luadraw}
\usepackage[svgnames]{xcolor}
\usepackage{fourier-otf}
\begin{document}
\begin{luadraw}{name=tilted_hyperbola}
local ld = luadraw
local Z, i = ld.cpx.Z, ld.cpx.I
local sinh, cosh = math.sinh, math.cosh

local g = ld.graph:new{window = {-6, 6, -4, 7}}

local left_branch = function(t) return Z(-2 * cosh(t), sinh(t)) end
local right_branch = function(t) return Z(2 * cosh(t), sinh(t)) end

local plot_hyperbola = function(opt)
    g:Dline({0, 1}, "-Latex,ultra thick")
    g:Dline({0, i}, "-Latex,ultra thick")
    g:Dparametric(right_branch, {t = {-2.5, 2.5}, nbdots = 100,draw_options = opt})
    g:Dparametric(left_branch, {t = {-2.5, 2.5}, nbdots = 100,draw_options = opt})
    g:Dline({0, Z(1, 1 / 2)}, "dashed,"..opt)
    g:Dline({0, Z(1, -1 / 2)}, "dashed,"..opt)
end

plot_hyperbola("teal")

g:Savematrix()
g:Shift(Z(-2, 2))
g:Rotate(45)
plot_hyperbola("magenta")
g:Restorematrix()

g:Show()
\end{luadraw}
\end{document}

image.png

撰写答案

请登录后再发布答案,点击登录

发布
问题

分享
好友

手机
浏览

扫码手机浏览