使用正弦、余弦和正切等函数计算 Tikz 中的坐标

使用正弦、余弦和正切等函数计算 Tikz 中的坐标

我正在使用 pgfmanual 学习 TikZ。给出的示例如下:

在此处输入图片描述

到目前为止我已取得以下成果:

在此处输入图片描述

代码如下:

\documentclass{article}
\usepackage{tikz}

\tikzset{help lines/.style=very thin}
\tikzset{My Grid/.style={help lines,color=blue!50}}

\begin{document}
\begin{tikzpicture}
  \draw[My Grid] (-4,-4) grid (4,4);
  \draw (-5,0) node[left] {$(-5,0)$} -- (5,0) node[right] {$(5,0)$};
  \draw (0,-5) node[below] {$(0,-5)$} -- (0,5) node[above] {$(0,5)$};
  \draw (0,0)  circle [radius=3cm];
  \shadedraw[left color=gray, right color=green, draw=green!50!black] (0,0) -- (0.75,0)  arc [start angle=0, end angle=30, radius=1cm] -- cycle;
  \draw[red, very thick] (30:3cm) -- (2.6,0);
  \draw [very thick,orange] (3,0) -- (3,1.7);
\end{tikzpicture}
\end{document} 

为了实现斜率和切线的交点,pgfmanual 使用了路径和交叉点库的概念,这非常令人困惑。

有没有更简单的方法告诉系统从点 A 到 sin(30) 画一条线作为点 B,并按比例绘制角度的正切,而不是使用直接数字。

请建议除交叉点、极坐标和路径之外的替代方案。因为 pgfmanual 已经使用了它们,这很难理解。

答案1

由于和中cos(30)tan(30)括号,因此必须将这些函数放在花括号内{}

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{angles,quotes}

\tikzset{help lines/.style=very thin}
\tikzset{My Grid/.style={help lines,color=blue!50}}

\begin{document}
\begin{tikzpicture}
  \draw[My Grid] (-4,-4) grid (4,4);
  \draw (-5,0) node[left] {$(-5,0)$} -- (5,0) node[right] {$(5,0)$};
  \draw (0,-5) node[below] {$(0,-5)$} -- (0,5) node[above] {$(0,5)$};
  \draw (0,0)  circle [radius=3cm];

%   \shadedraw[left color=gray, right color=green, draw=green!50!black]
% (0,0) -- (0.75,0)  arc [start angle=0, end angle=30, radius=0.75cm] --  cycle;

  \coordinate(O)at(0,0);
  \draw[red, very thick] (30:3cm)coordinate(A) 
                         --({3*cos(30)},0)coordinate(B);

  \draw [very thick,orange] (3,0) -- (3,{3*tan(30)})coordinate(C);

  \pic[fill=green!50!black,
       angle radius=0.75cm,
       angle eccentricity=1.2,
       "\(\alpha\)"] {angle=B--O--A};

   \draw (O)--(C);

\end{tikzpicture}
\end{document} 

在此处输入图片描述

答案2

这是替代方案Hafid 的精彩回答,进一步朝着你开始的方向前进。你不需要使用任何三角函数。只需使用极坐标和投影就足够了。

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc,angles,quotes}
\tikzset{help lines/.style=very thin}
\tikzset{My Grid/.style={help lines,color=blue!50}}

\begin{document}
\begin{tikzpicture}
  \draw[My Grid] (-4,-4) grid (4,4);
  \draw (-5,0) node[left] {$(-5,0)$} -- (5,0) node[right] {$(5,0)$};
  \draw (0,-5) node[below] {$(0,-5)$} -- (0,5) node[above] {$(0,5)$};
  \draw (0,0) coordinate (O)  circle [radius=3cm];
  \draw[red, very thick] (30:3cm) coordinate (A) 
  % (30:3cm) is a polar coordinate with angle 30 (degrees) and radius 3cm
  -- (0,0-|A) coordinate(Ax)
  %  (0,0-|30:3cm) is a point that has the x coordinate of A and y=0
  % see https://tex.stackexchange.com/a/401429/121799 for more details
  node[midway,left]{$\sin\alpha$};
  \draw [very thick,orange] (3,0) -- (intersection cs:
  first line={(O)--(A)},second line={(3,0)--(3,3)}) coordinate(A')
  % (A') is at the intersections of the lines OA and the vertical line through (3,0)
  node[midway,right]{$\tan\alpha$};
  \pic[fill=green!50,angle radius=1cm,
       angle eccentricity=0.6, "$\alpha$"] {angle=Ax--O--A};
  % that's almost a 1-1 copy of what you can find on p. 560 of the manual      
  \draw (O) -- (A');
  \draw[very thick,blue] (O) -- (Ax) node[midway,below]{$\cos\alpha$};
\end{tikzpicture}
\end{document} 

在此处输入图片描述

相关内容