直角座標系中的點 - 將座標指定為函數值

直角座標系中的點 - 將座標指定為函數值

我正在嘗試定位矩形的頂點並為矩形區域著色。我將 y 座標指定為函數值,例如\sqrt{3}/2\sin(60)。我收到錯誤。

\documentclass{amsart}
\usepackage{tikz}
\usetikzlibrary{calc}


\begin{document}
\begin{tikzpicture}

\coordinate (A) at (-1,{-\sqrt{3}/2});
\coordinate (B) at (-1,{\sin(60)});
\coordinate (C) at (2,{\sin(60));
\coordinate (D) at (2,{-\sqrt{3}/2});

\path[fill=yellow] (A) -- (B) -- (C) -- (D) -- cycle;

\node[outer sep=0pt,circle, fill,inner sep=1.5pt,label={[fill=white]below left:$A$}] at (A) {};
\node[outer sep=0pt,circle, fill,inner sep=1.5pt,label={[fill=white]above left:$B$}] at (B) {};
\node[outer sep=0pt,circle, fill,inner sep=1.5pt,label={[fill=white]above right:$C$}] at (C) {};
\node[outer sep=0pt,circle, fill,inner sep=1.5pt,label={[fill=white]below right:$D$}] at (D) {};
\end{tikzpicture}

答案1

雖然TikZ/pgf用在 中,但它的語法是特殊的,就像的數學引擎LaTeX的語法一樣。pgf

在這種特殊情況下,諸如sqrtor之類的函數不以(反斜線)sin開頭。\需要括號的複合參數必須用 括起來{...}。正確的定義代碼coordinates應該是:

\coordinate (A) at (-1,{-sqrt(3)/2}); 
\coordinate (B) at (-1,{sin(60)});
\coordinate (C) at (2,{sin(60)});
\coordinate (D) at (2,{-sqrt(3)/2});

相關內容