使用正弦、餘弦和正切等函數計算 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

由於 incos(30)tan(30)there 有括號,因此您必須將這些函數放在大括號內{}

\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

這是一個替代方案海菲德的回答很好,朝著您開始的方向進一步前進。您不需要使用任何三角函數。僅使用極坐標和投影就足夠了。

\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} 

在此輸入影像描述

相關內容