标记(多个)交点正弦函数和常数函数

标记(多个)交点正弦函数和常数函数

正弦函数与常数函数的交点有多个结果。所以我的问题是如何标记这些点。我的代码

\documentclass[11pt,a4paper]{article} 
\usepackage{geometry}
\geometry{margin=1in} 

\usepackage{tikz}
\usepackage{tkz-euclide}
\usetkzobj{all} %% om allerhande objecten te gebruiken zoals gradenboog...
\usetikzlibrary{calc,intersections,through,backgrounds,snakes}
\usepackage{pgfplots}
\pgfplotsset{compat=1.8}

\begin{document}

\begin{center}
\begin{tikzpicture}
\begin{axis}[
   %at={(0,-12mm)},
    y=10mm,
    width=1*\textwidth,
    axis lines=center,
    xmin=0, xmax=4*pi,
    ymin=-2, ymax=2,
    enlarge y limits,
    enlarge x limits=upper,
    samples=50,
    xtick={0,1.5708,...,22},
    ytick={-2,-1,...,3},
    xticklabels={0, $\frac{\pi}{2}$, $\pi$, $\frac{3\pi}{2}$,$2\pi$,$\frac{5\pi}{2}$, $3\pi$, $\frac{7\pi}{2}$, $4\pi$,$\frac{9\pi}{2}$, $5\pi$, $\frac{11\pi}{2}$, $6\pi$,$\frac{13\pi}{2}$, $7\pi$},
    tick label style={font=\tiny},
    ]
    \addplot[smooth, domain=0:4*pi, very thick, red] {sin(deg(x))};
    \addplot[smooth, domain=0:4*pi] {0.5};
\end{axis}
\end{tikzpicture}
\end{center}    
\end{document}

sin(x)=0.5

答案1

(可能有更优雅的方法来实现这一点。)您可以使用name path global给每条情节线贴上标签,并name intersections(从intersections库中)找到它们之间的交点。这两者都来自 TikZ,因此请参阅该手册了解更多信息。

在此处输入图片描述

\documentclass[11pt,a4paper]{article} 
\usepackage{geometry}
\geometry{margin=1in} 

\usepackage{tikz}
\usepackage{tkz-euclide}
\usetkzobj{all} %% om allerhande objecten te gebruiken zoals gradenboog...
\usetikzlibrary{calc,intersections,through,backgrounds,snakes}
\usepackage{pgfplots}
\pgfplotsset{compat=1.8}

\begin{document}

\begin{center}
\begin{tikzpicture}
\begin{axis}[
   %at={(0,-12mm)},
    y=10mm,
    width=1*\textwidth,
    axis lines=center,
    xmin=0, xmax=4*pi,
    ymin=-2, ymax=2,
    enlarge y limits,
    enlarge x limits=upper,
    samples=50,
    xtick={0,1.5708,...,22},
    ytick={-2,-1,...,3},
    xticklabels={0, $\frac{\pi}{2}$, $\pi$, $\frac{3\pi}{2}$,$2\pi$,$\frac{5\pi}{2}$, $3\pi$, $\frac{7\pi}{2}$, $4\pi$,$\frac{9\pi}{2}$, $5\pi$, $\frac{11\pi}{2}$, $6\pi$,$\frac{13\pi}{2}$, $7\pi$},
    tick label style={font=\tiny},
    ]
    \addplot[smooth, domain=0:4*pi, very thick, red,name path global=sine] {sin(deg(x))};
    \addplot[smooth, domain=0:4*pi,name path global=straight] {0.5};

\path [draw,name intersections={of={sine and straight}}]
  (intersection-1) circle[radius=2pt]
  (intersection-2) circle[radius=2pt]
  (intersection-3) circle[radius=2pt]
  (intersection-4) circle[radius=2pt];
\end{axis}    
\end{tikzpicture}
\end{center}    
\end{document}

相关内容