在图表中使用覆盖命令

在图表中使用覆盖命令

我有一张以原点为中心的圆的一部分、一个标记为“alpha”的角度、一个半径和两条线段的图表,其中的端点在 x 轴上。它应该有以下两个修改。(第一个修改涉及命令的使用overlay。)

如图所示,标签(或节点)“P = (r\cos\alpha, \, r\sin\alpha)”与 x 轴和 Q 之间的虚线段相冲突。它应该位于此线段上的矩形节点中。(如果标签相对于 P 位于西北位置,则它应该位于圆上的矩形节点中。)

角度 \alpha 应位于弧的中间。

\documentclass[border=10pt]{standalone}%
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{calc,positioning,intersections}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\def\ang{50} % 0< \ang<90

\begin{document}


\begin{center}
\begin{tikzpicture}[
dot/.style={
fill,
circle,
inner sep=1.5pt
}
]
\clip (-1,-1) rectangle (7,7);
\draw[dashed,fill=white,name path=curve] (0,0) coordinate(O){} circle [radius=4];
\draw[<->] (-5,0) -- (5,0) node[below] {$x$};
\draw[<->] (0,-5) node (yaxis) {} -- (0,5) node[right] {$y$};

\path[name path=lineb] (0,0) -- (\ang:5);
\path[dashed] (0,0) -- (\ang:7);
\draw[dashed] (0,0) -- (4,4.76701437);
\draw[dashed] (4,0) -- (4,4.76701437);
\draw[dashed] (2.5711504,0) -- (2.5711504,3.06417777);
\node[dot,label={right:$P=(r\cos\alpha, \, r\sin\alpha)$}] at (2.5711504,3.06417777) {};
\node[dot,label={right:$Q=(r, \, r\tan\alpha)$}] at (4,4.76701437) {};
\draw[->] (0,0) --node[pos=1.25,above]{$\alpha$} (0.8,0) arc (0:\ang:0.8cm) ;


\path[name path=linec] (2,0) -- (2,3); 
\draw[name intersections={of=lineb and linec, by={c}},thick]{};
\end{tikzpicture}
\end{center}

\end{document}

答案1

对于第一个问题(标签干扰虚线),您可以使用every label/.style为标签定义白色背景。

对于第二个( \alpha 应该位于圆弧的中间),您可以使用另一个arc具有一半角度和稍大半径的圆弧。

结果:

\documentclass{article}%
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{calc,positioning,intersections}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\def\ang{50} % 0< \ang<90

\begin{document}


\begin{center}
\begin{tikzpicture}[
dot/.style={
fill,
circle,
inner sep=1.5pt
},
every label/.style={fill=white},
]
\clip (-1,-1) rectangle (7,7);
\draw[dashed,fill=white,name path=curve] (0,0) coordinate(O){} circle [radius=4];
\draw[<->] (-5,0) -- (5,0) node[below] {$x$};
\draw[<->] (0,-5) node (yaxis) {} -- (0,5) node[right] {$y$};

\path[name path=lineb] (0,0) -- (\ang:5);
\path[dashed] (0,0) -- (\ang:7);
\draw[dashed] (0,0) -- (4,4.76701437);
\draw[dashed] (4,0) -- (4,4.76701437);
\draw[dashed] (2.5711504,0) -- (2.5711504,3.06417777);
\node[dot,label={right:$P=(r\cos\alpha, \, r\sin\alpha)$}] at (2.5711504,3.06417777) {};
\node[dot,label={right:$Q=(r, \, r\tan\alpha)$}] at (4,4.76701437) {};
\draw[->] (0.8,0) arc [start angle=0, end angle=\ang, radius=0.8cm] ;
\path (1.0,0) arc [start angle=0, end angle=25, radius=1.0cm] node {$\alpha$};


\path[name path=linec] (2,0) -- (2,3); 
\draw[name intersections={of=lineb and linec, by={c}},thick]{};
\end{tikzpicture}
\end{center}

\end{document}

在此处输入图片描述

答案2

元帖子你可以用运算符计算出所有这些正弦和余弦值rotated,这个z$=(x$,y$)惯例很方便。清除标签后面的框需要多做一点工作,如下所示,如第 9 节所述手册

在此处输入图片描述

prologues := 3;
outputtemplate := "%j%c.eps";

beginfig(1);

r := 100;     % radius of the arc
alpha := 50;  % angle of rotation
margin := 24; % overshoot for the axes

z1 = (r,0) rotated alpha; % point P
z2 = (q,0) rotated alpha; % point Q, (q is just a dummy variable)
x2 = r;

drawoptions(dashed evenly);
draw origin -- z2;
draw (x1,0) -- z1;
draw (x2,0) -- z2;
draw subpath (-1, 3) of fullcircle scaled 2r
     cutbefore ((-margin,-margin) -- (r+margin,-margin))
     cutafter  ((-margin,-margin) -- (-margin,r+margin));
drawoptions();

% label the points
dotlabel.rt(btex $Q=(r, r\tan\alpha)$ etex, z2);
% dotlabel.rt(btex $P=(r\cos\alpha,r\sin\alpha)$ etex, z1);
% but this makes a mess of the lines, so do it by hand and unfill behind
fill fullcircle scaled dotlabeldiam shifted z1;
picture P; P = thelabel.rt(btex $P=(r\cos\alpha,r\sin\alpha)$ etex, z1+(6,0));
unfill bbox P; draw P;

% axes
drawarrow (0,-margin) -- (0,r+margin); label.rt (btex $y$ etex, (0,r+margin));
drawarrow (-margin,0) -- (r+margin,0); label.bot(btex $x$ etex, (r+margin,0));

% angle mark
path mark; mark = (20,0) { up } .. { up rotated alpha } (20,0) rotated alpha;
drawarrow mark; label.rt(btex $\alpha$ etex, point .5 of mark);

endfig;
end.

答案3

由于您正在加载,因此pgfplots我将其视为答案的开始信号pgfplots:) 优点是您可以精确绘制图并将节点准确放置在标签所示的位置。并且您可以使用角度库来标记角度,而且它更简洁,因为您不需要处理轴,也不intersections需要。缺点是您需要对pgfplots坐标系和轴选项有一点熟悉。

我把标签放在最后要绘制的东西上,这样fill=white就足够了。另外,我认为坐标方程不是那么清晰的符号,所以把它转换成了矢量。

\documentclass{standalone}
\usepackage{pgfplots,mathtools}
\pgfplotsset{compat=1.10}
\usetikzlibrary{positioning,angles,quotes}

\def\myang{50} % 0< \ang<90
\def\myradius{3}
\begin{tikzpicture}[dot/.style={fill,circle,inner sep=1.5pt}]
\begin{axis}[axis lines=middle,xlabel=$x$,ylabel=$y$,
          xtick=\empty,ytick=\empty,
          xmax=\myradius*1.5,ymax=\myradius*1.5,
          axis equal,
          clip=false]
\addplot[dashed,domain=-pi/10:6*pi/10] ({\myradius*cos(deg(x))},{\myradius*sin(deg(x))});
%Place coordinates
  \coordinate (O) at (axis cs:0,0);
  \node[dot] at (axis cs:{\myradius*cos(\myang)},{\myradius*sin(\myang)}) (P) {};
  \node[dot] at (axis cs:{\myradius},{\myradius*tan(\myang)}) (Q) {};
  \draw[dashed] (O) -- (Q) -- (Q |- O) coordinate(Qp) (P) -- (P |- O);
% Mark the angle
  \pic["$\alpha$", draw,->,angle eccentricity=1.2,angle radius=1cm] {angle=Qp--O--Q};
% Place the node descriptions
  \node[fill=white,inner sep=1pt,right= 1.2 mm of P] 
      {$P\begin{psmallmatrix}r\cos\alpha\\ r\sin\alpha\end{psmallmatrix}$};
  \node[right= 1mm of Q] {$Q\begin{psmallmatrix}r\\ r\tan\alpha\end{psmallmatrix}$};

\end{axis}
\end{tikzpicture}
\end{document}

在此处输入图片描述

答案4

这是使用fill=white公式标签的另一种解决方案。我还尝试美化代码并让内部进行数学运算。如果您需要更多信息,请询问。

更新版本 - 查看更改历史记录

\documentclass[border=5mm, tikz]{standalone}
\usetikzlibrary{calc}

\begin{document}
\begin{tikzpicture}
 \tikzset{
    >=latex,
    dot/.style={
        fill,
        circle,
        inner sep=1.5pt,
    },
    axis/.style={
        ->,
        thick,
    },
    label/.style={
        right=.25cm,
        fill=white,
    },
 }

 % define angle and radius
 \newcommand{\myradius}{4cm}
 \newcommand{\myangle}{50}

 % x- and y-axis
 \draw [axis] (-.5,0) -- ++(6,0) node [below] {$x$};
 \draw [axis] (0,-.5) -- ++(0,6) node [right] {$y$};

 % arc with radius
 \draw [dashed] (0,0) + (-15:\myradius) arc (-15:105:\myradius);

 % coordinates of p and q
 \coordinate (p) at (\myradius * cos \myangle, \myradius * sin \myangle) node at (p) [dot] {};
 \coordinate (q) at (\myradius, \myradius * tan \myangle) node at (q) [dot] {};

 % lines from p and q 
 \draw [dashed] (q) -- (0,0);
 \draw [dashed] (q) -- (\myradius,0);
 \draw [dashed] (p) -- ($(0,0)!cos \myangle!(\myradius,0)$);

 % labels at p and q
 \node at (p) [label] {$P={r \cos \alpha \choose r \sin \alpha}$};
 \node at (q) [label] {$Q={r \choose r \tan \alpha}$};

 % alpha and r labels
 \draw [->] (.8,0) arc (0:\myangle:.8cm);
 \node at ($(0,0) + (\myangle/2:1cm)$) {$\alpha$};
 \draw [->] (0,0) -- ++(-5:\myradius) node [below left] {$r$}; 
\end{tikzpicture}
\end{document}

渲染图像: 渲染图像

相关内容