使用長度和角度繪製三角形?

使用長度和角度繪製三角形?

我只是想了解 tikz 點網格,並設法使用這種方法繪製三角形,但是有沒有一種方法可以透過直接輸入線長度和角度來繪製?

例如,如果我想要 125 度、40 度和 15 度的角度,斜邊為 15 厘米,我該如何設定?

答案1

為了進行比較,這裡有一個使用 Metapost 的替代方法。 (程式碼是 ConTeXt 程式碼,但您也可以使用該套件在 LaTeX 中使用 Metapost 程式碼gmp)。

在 Metapost 中,可以使用關鍵字指定未知的數值whatever。 Metapost 計算出 s 的值,whatever以便滿足所有方程式。

讓我們將三角形的頂點標記為ABC。假設我們要繪製AB平行於 x 軸的AC斜邊,角度A為 40,角度B為 125 C。我們可以在 Metapost 中將其指定為:

numeric angleA, angleB;
angleA := 40;
angleB := 125;

numeric AC;
AC := 15cm;

我們選擇點A作為原點。那麼點C就完全指定了

pair A, B, C;

A := origin;
C := (AC,0) rotated angleA;

為了指定點B,我們給出 的兩個方程式B。首先是B沿著x 軸AB的距離,即A

B = (whatever, 0);

其次,CB應該是一個角度B,即

B = ((whatever,0) rotated -angleB) shifted C;

Metapost 為這兩種規範找到了一致的解決方案。這是完整的程式碼:

\starttext
\startMPpage[offset=3mm]
  begingroup;
    numeric angleA, angleB, angleC;
    angleA := 40;
    angleB := 125;

    numeric AC;
    AC := 15cm;

    pair A, B, C;

    A := origin;
    C := (AC,0) rotated angleA;

    % Let Metapost figure out B.
    B = (whatever, 0);
    B = ((whatever,0) rotated -angleB) shifted C;

    path triangle ;
    triangle := A -- B -- C --cycle;

    draw triangle;

    pair c; c := center triangle;

    freedotlabel("$A$", A, c);
    freedotlabel("$B$", B, c);
    freedotlabel("$C$", C, c);

  endgroup;
\stopMPpage
\stoptext

這使

在此輸入影像描述

答案2

像這樣?

\documentclass[margin=1cm]{standalone}

\usepackage{tikz}
\usetikzlibrary{intersections}

\begin{document}
  \begin{tikzpicture}
  \def\angf{40} %First angle
  \def\angs{125} %Second angle
  \def\hypo{15} %Hypotenus
  \coordinate (O) at (0,0);
  \draw[name path=line 1] (O) --++ (\angf:\hypo) coordinate (A);
  \path[name path=line 2] (O) --++ (0:2\hypo);
  \path[name path=line 3] (A) --++ (-\angs:2\hypo);
  \path [name intersections={of=line 2 and line 3,by=E}];
  \pgfresetboundingbox
  \draw (O)--(E)--(A);
  \end{tikzpicture}
\end{document}

在此輸入影像描述

答案3

了解你的數學!

角度-長度關係由下式給出正弦定理

輸出

在此輸入影像描述

程式碼

\documentclass[12pt,tikz]{standalone}
\begin{document}
\begin{tikzpicture}[scale=.5]
  % "hypothenuse"
  \def\A{15}
  % the angles
  \def\angA{125}
  \def\angB{40}
  \pgfmathsetmacro{\angC}{180-\angA-\angB}
  % the law of sines
  \pgfmathsetmacro{\d}{\A/sin(\angA)}
  \pgfmathsetmacro{\C}{\d*sin(\angC)}
  \draw (0,0) -- (\angB:\A) -- (0:\C) -- cycle;
\end{tikzpicture}
\end{document}

相關內容