用`tikz`中的`polt`绘制`y=sqrt{16/(x+2)^2-(x-2)^2}`的图像时最右端部分无法闭合?

发布于 2026-01-03 13:24:29

tikz中的polt绘制24年新I卷数学第11题的飘带函数

y=sqrt{16/(x+2)^2-(x-2)^2}

的图像时最右端部分无法闭合,定义域已正确设置,请问有谁指定是什么地方有问题吗?

1.PNG

2.PNG

查看更多

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

请给完整、可复制的代码。

代码不是看出来问题的,是复制,编译,多次测试debug之后才能解决的...

如果代码不可复制或不完整,别人测试就需要花费更多的时间...


\documentclass[tikz,border=5pt]{standalone}
\makeatletter
\def\tikz@plot@samples@recalc#1:#2\relax{%
  \pgfmathparse{#1}%
  \let\tikz@temp@start=\pgfmathresult%
  \pgfmathparse{#2}%
  \let\tikz@temp@end=\pgfmathresult%
  \pgfmathparse{\tikz@temp@start + (\tikz@temp@end - \tikz@temp@start) / (\tikz@plot@samples - 1)}
  \edef\tikz@plot@samplesat{\tikz@temp@start, \pgfmathresult, ..., \tikz@temp@end, \tikz@temp@end}
}
\makeatother
\begin{document}
\begin{tikzpicture}[very thin,domain=-1:{2*sqrt(2)}]
\draw[-stealth] (-1.5,0)--(3,0)node[scale=0.7,right]{$x$};
\draw[-stealth] (0,-3)--(0,3)node[scale=0.7,left]{$y$};
\node[label={[anchor=north east,yshift=-.1em]$o$}] {};
\draw plot[samples=300] (\x,{sqrt(16/(\x+2)^2-(\x-2)^2)});
\draw plot[samples=300] (\x, {-sqrt(16/(\x+2)^2-(\x-2)^2)});
\end{tikzpicture}
\end{document}

image.png

Sagittarius Rover
这家伙很懒,什么也没写!

基于luadraw宏包:

Notes: 需要自行安装、使用lualatex编译...

\documentclass[border=4pt]{standalone}
\usepackage{luadraw}
\begin{document}
\begin{luadraw}{name=implicit_function}
    local g = graph:new{
        window={-1,3.5,-2,2},size={10,10}
    }
    g:Linecap("round");g:Linewidth(8)
    local F = function(x,y) return (x-2)^2+y^2-16/((x+2)^2) end
    g:Dimplicit(F,{grid={500,500},draw_options="thick"})
    g:Daxes(
        {0,4,3},{
            arrows="-stealth",
            labelpos={"top","right"},
            originpos={"none","none"}
        }
    )
    g:Show()
\end{luadraw}
\end{document} 

image.png

image.png

越来越少
越来越少 1天前
这家伙很懒,什么也没写!

如果用 tikz 的话, 建议分段绘制.

f(x) = sqrt(16 / (x + 2)^2 - (x - 2)^2), -1 <= x <= 0,
g(x) = sqrt(16 / (x + 2)^2 - (x - 2)^2), 0 <= x <= 2.6,
h(x) = sqrt(16 / (x + 2)^2 - (x - 2)^2), 2.6 <= x <= 2*sqrt(2),

这条曲线在 (0,0) 点处不光滑, 在 (2*sqrt(2),0) 处导数值无穷, 适合分段

\documentclass[tikz,border=5pt]{standalone}
\usepackage{xfp}
\begin{document}
\begin{tikzpicture}[line cap=round]
\draw[-stealth] (-1.5,0)--(3,0)node[scale=0.7,right]{$x$};
\draw[-stealth] (0,-3)--(0,3)node[scale=0.7,left]{$y$};
\node[label={[anchor=north east,yshift=-.1em]$o$}] {};

\def\sp{2.6}%第二, 三段的分点
\def\sampleNOa{10}\edef\stepa{\fpeval{1/\sampleNOa}}%第一段的点数量, 自变量步长
\def\sampleNOb{30}\edef\stepb{\fpeval{\sp/\sampleNOb}}%第二段的点数量, 自变量步长
\def\sampleNOc{60}\edef\stepc{\fpeval{(2*sqrt(2)-\sp)/\sampleNOc}}%第三段的点数量, 自变量步长

\foreach \z/\p in {a/-1,b/0,c/\sp}{
    \expandafter\let\expandafter\sampleNO\csname sampleNO\z\endcsname
    \expandafter\let\expandafter\step\csname step\z\endcsname
    \edef\PL{\fpeval{\p,sqrt(16/(\p+2)^2-(\p-2)^2)}}
    \foreach \i in {1,2,...,\sampleNO}{
        \xdef\PL{\PL \fpeval{\p + \i*\step, sqrt(16 / (\p + \i*\step + 2)^2 - (\p + \i*\step - 2)^2)}}
    }
    \draw plot[smooth] coordinates {\PL};
}
\end{tikzpicture}
\end{document}

3af1980e7741fe8cc581c4115da4e84e.png

如果能求出 h(x) 的反函数, 或者曲线的参数表示, 需要绘制的点的数量还可能会更少.

撰写答案

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

发布
问题

分享
好友

手机
浏览

扫码手机浏览