Advertisement

如何用LaTeX Tikz畫幾何圖

阅读量:

我這樣理解Tikz——

Tikz使用笛卡爾座標系和極座標表示一個點。

用\coordinate命令畫一個確定的點,但默認地,這個點像是像鉛筆在紙上點了一下,沒印出什麼來,直徑為零。如果要肉眼看到這個點,就用circle標出來。

用\node也可以畫一個點,但這個命令用途很廣,什麼圖案都可以是一個node。有時node占的空間大,不如coordinate精確,以我目前的理解,node是無法替代coordinate命令的。

本文的目標是給出一個可行的解決方案,是一個子集。

在coordinate確定點後,畫線用draw命令。也可以用path命令,但path命令默認是一個不可見的線段、三角形三條邊甚至一條曲線,path是圖論中的路徑的概念,一條通過多個節點的所經之路即path。我把draw當畫直線用,也可以用control參數畫曲線,但我沒有弄懂確切如何使用。我目前只當畫直線用。如此,我還不知道draw命令能否完全替代path。

在我有限的幾何圖繪畫中path用在畫角平分線,三角形的三條邊是一個path,從頂點畫一個圓,交兩條邊於兩個點,連接這兩個點,取中點,頂點連中點即角平分線。

角的示意符號使用pic參數,但如果不用,自己畫圓弧或者直角示意符號也是可以的。

關於函數如何繪畫,比如拋物線,我只是拷貝例子,還沒有自己使用。

我尚未整理所有的參考文檔,只在代碼註釋中。

過去我想著用Python畫圖,但初等數學能用LaTeX一種語言寫完,為什麼要多用一種計算機語言?這對非計算機專業的絕大多數人來說,不合適。所以我決定學習LaTeX畫幾何圖。本文是初稿。

LaTeX studio網站給出了很多複雜的圖形。我學習了其中全等三角形和相似三角形的符號。

我只貼PDF部分截圖。最後是LaTeX code,上傳文檔名為tikz_euclid_20250419.tex。
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述在这里插入图片描述以下是LaTeX code。

复制代码
    % https://tikz.dev/tutorial-Euclid
    % Typeset: XeLaTeX
    \documentclass[12pt]{article}
    \usepackage[margin=1in]{geometry}%設置頁邊距
    
    \usepackage{ctex}%中文
    \setCJKmainfont{Alibaba PuHuiTi}   % 中文字體
    \usepackage{fontspec}   %英文
    \setmainfont{Verdana}   % 英文字體
    \renewcommand{\baselinestretch}{1.5} % 設置1.5倍行距
    
    \usepackage{hyperref}%支持鏈接可點擊
    \usepackage[style=iso]{datetime2}%設置日期格式為YYYY--MM--DD
    
    \usepackage{amsmath, amsfonts, amssymb}
    \usepackage{tikz}
    \usepackage{pgfplots}
    \usetikzlibrary{arrows}
    \usetikzlibrary{datavisualization.formats.functions}
    
    % 全等符號 \backcong和相似符號\backsim
    
    %來源:厚德载物,『tikz绘制的全等与相似符号』,2022-07-25,https://www.latexstudio.net/index/details/index/mid/2816.html
    %%%%%%%全等符号 定義開始%%%%%%%
    \newcommand{ \usimeq}{\;
    	\begin{tikzpicture}[line width = 0.1 ex, line cap = round, shift={(1. 473ex, 1ex)}]
    	\draw (-0.1146ex, -0.2ex) arc (330:90:0. 4ex);
    	\draw (0.1146ex, 0.2ex) arc (150: -90:0.4ex);
    	\draw (-0.1146ex, -0.2ex) -- (0.1146ex, 0.2ex);
    	\draw (-0.9ex, -1.1ex) -- (0.9ex, -1.1ex);
    	\draw [yshift = 0.35ex] (-0.9ex, -1.1ex) -- (0.9ex, -1.1ex);
    	\end{tikzpicture}\;} 
    %%%%%%%全等符号 定義結束%%%%%%%
    
    %%%%%%%相似符号 定義開始%%%%%%%
    \newcommand{ \usim}{\;
    \begin{tikzpicture}[line width = 0.1 ex, line cap = round, shift={(1. 473ex, 1ex)}]
    \draw (-0.1ex, -0.25ex) arc (330:90:0.5ex);
    \draw (0.1292ex, 0.25ex) arc (150: -90:0.5ex);
    \draw (-0.1ex, -0.25ex) -- (0.1292ex, 0.25ex);
    \end{tikzpicture}\;} 
    %%%%%%%相似符号 定義結束%%%%%%%
    \parindent 0pt
    
    %Example enviroment. Typeset the source code and print it in the PDF as well.
    %https://tex.stackexchange.com/questions/240642/add-vertical-line-of-equation-x-2-and-shade-a-region-in-graph-by-pgfplots
    \usepackage{fancyvrb-ex}
    
    \title{\Huge\textbf{如何用LaTeX Tikz畫幾何圖}}
    \author{}
    \begin{document}
    \maketitle
    
    我這樣理解Tikz——
    
    Tikz使用笛卡爾座標系和極座標表示一個點。
    
    用\verb"\coordinate"命令畫一個確定的點,但默認地,這個點像是像鉛筆在紙上點了一下,沒印出什麼來,直徑為零。如果要肉眼看到這個點,就用circle標出來。
    
    用\verb"\node"也可以畫一個點,但這個命令用途很廣,什麼圖案都可以是一個node。有時node占的空間大,不如coordinate精確,以我目前的理解,node是無法替代coordinate命令的。
    
    本文的目標是給出一個可行的解決方案,是一個子集。
    
    在coordinate確定點後,畫線用draw命令。也可以用path命令,但path命令默認是一個不可見的線段、三角形三條邊甚至一條曲線,path是圖論中的路徑的概念,一條通過多個節點的所經之路即path。我把draw當畫直線用,也可以用control參數畫曲線,但我沒有弄懂確切如何使用。我目前只當畫直線、圓弧用。如此,我還不知道draw命令能否完全替代path。
    
    在我有限的幾何圖繪畫中path用在畫角平分線,三角形的三條邊是一個path,從頂點畫一個圓,交兩條邊於兩個點,連接這兩個點,取中點,頂點連中點即角平分線。
    
    角的示意符號使用pic參數,但如果不用,自己畫圓弧或者直角示意符號也是可以的。
    
    關於函數如何繪畫,比如拋物線,我只是拷貝例子,還沒有自己使用。
    
    我甚至尚未整理所有的參考文檔,只在代碼註釋中。
    
    過去我想著用Python畫圖,但初等數學能用LaTeX一種語言寫完,為什麼要多用一種計算機語言?這對非計算機專業的絕大多數人來說,不合適。所以我決定學習LaTeX畫幾何圖。本文是初稿。
    
    \href{https://www.latexstudio.net}{LaTeX studio網站}給出了很多複雜的圖形。我學習了其中全等三角形和相似三角形的符號。
    
    \section{如何在某一座標畫一個點}
    
    
    \begin{Example}[frame=single, numbers=left]
    \tikz \coordinate[shape=circle, fill=black, opacity=.5, %
    inner sep=1pt] (A) at (0,0);
    \end{Example}
    
    % 座標表示 https://tikz.dev/tikz-design
    \subsection{座標表示方法}
    
    \begin{Example}[frame=single]
    \tikz \draw (0,0) node[shape=circle, inner sep=1pt, %
    fill=black!50,label=left:$A$] {} -- ++(1,0) -- (30:1cm);
    %++(1,0)是相對座標,X軸右移1unit。(30:1cm)是極座標,30度角,半徑1cm。
    \end{Example}
    
    
    \section{如何畫一條線}
    \begin{Example}[frame=single]
    \begin{tikzpicture}
    \coordinate [label=left:\textcolor{orange}{$A$}]  (A) at (0,0);
    \coordinate [label=right:\textcolor{blue!80!black}{$B$}] (B) at (1,0.2);
    \draw [red, thick] (A)--(B);
    %
    \coordinate [label=left:\textcolor{orange}{$A$}]  (A) at (2,0);
    \coordinate [label=right:\textcolor{blue!80!black}{$B$}] (B) at (3,0.2);
    \path[draw=red, thick]
    (A) -- (B);
    %
    \coordinate [label=left:\textcolor{orange}{$A$}]  (A) at (4,0);
    \coordinate [label=right:\textcolor{blue!80!black}{$B$}] (B) at (5,0.2);
    \path
    (A) edge [red, thick]  (B);
    \end{tikzpicture}
    \end{Example}
    %
    \section{如何畫一個三角形}
    \begin{Example}[frame=single]
    \begin{tikzpicture}[roundpoint/.style={shape=circle, fill=black,%
     opacity=.5, inner sep=1pt}]
    % 第一種方法\coordinate定點,\fill circle畫小圓點
    	\coordinate [roundpoint, label=left:\textcolor{orange}{$A$}] %
    	 (A) at (0,0);
    	\coordinate [roundpoint, label=right:\textcolor{blue!80!black}%
    	{$B$}](B) at (1,0.2);
    	\coordinate [roundpoint,label=above:\textcolor{red!80!black}{$C$}]%
    	 (C) at (1,2);
    	\draw [thin,draw=black!50] (A) -- (B) -- (C) -- (A);
    %	\foreach \point in {A,B,C}
    %    		\fill [black,opacity=.5] (\point) circle (2pt);
    %
    % 第2種方法 lable的方位用度數表示,X軸正向為0度。    		
    	\coordinate [label=180:\textcolor{orange}{$A$}]  (A) at (2,0);
    	\coordinate [label=0:\textcolor{blue!80!black}{$B$}] (B) at (3,0.2);
    	\coordinate [label=90:\textcolor{red!80!black}{$C$}] (C) at (3,2);
    	\draw [thin,draw=black!50] (A) -- (B) -- (C) --(A);
    	\foreach \point in {A,B,C}
    		\fill [black!50] (\point) circle (1pt);
    % 第3種方法 \node直接畫一個小圓點
    \node [shape=circle, fill=black, opacity=.5, inner sep=1pt,%
    label=left:$A$] (A) at (4,0) {};
    \node [shape=circle, fill=black, opacity=.5, inner sep=1pt,%
    label=right:$B$] (B) at (5,0.2) {};
    \node [shape=circle, fill=black!50, inner sep=1pt,%
    label=above:$C$] (C) at (5,2) {};
    \draw[thin, black!50] (A) -- (B) -- (C) -- (A);
    %
    % 第4種方法 \draw (x,y) node直接畫一個小圓點, \path[draw]即\draw,
    %但是\pah支持--cycle這個參數。
    %
    % 為了減少重複的語句,定義style。
    % 定義style有兩種辦法:
    % 1)\tikzset定義style可以在tikzpicture envionment之內,或之外。
    % 2)在\begin{tikzpicure}[littlepoint/.style=……]可以定義style。
    % 但另起\begin{tikzpicure}就換行了。如果可以發現,換行後,座標不起作用,
    % 座標在Latex編譯中是相對位置。
    %
    \tikzset{littlepoint/.style={shape=circle, inner sep=1pt, fill=black!50}}
    \path[draw=black!50] (6,0) node[littlepoint,label=left:$A$] {} -- (7,0.2) 
    node[littlepoint,label=right:$B$] {} -- (7,2) 
    node[littlepoint,label=above:$C$]{} -- cycle;
    %  
    %綜合以上4種方法:用\coordinate定點畫點,或用\node定點畫點,\draw畫線,
    %這樣比較清晰,我選第1或3種方法。                   
    \end{tikzpicture}
    \end{Example}
    
    \section{如何畫一個矩形}
    \begin{Example}[frame=single]
    % https://tikz.dev/tikz-design
    \begin{tikzpicture}
    \path[draw=black!50] (5pt,0pt) -- (0pt,0pt) -- %
    (0pt,5pt) -- cycle;
    \path[draw=red] (1,0) rectangle (3,5);
    \path[fill=black!50,draw=blue] (4,1) rectangle (5,4);
    %\path[draw,clip] (1,1) rectangle (2,4);
    %clip表示裁剪一個矩形框。
    \draw[yellow] (6,6) rectangle (2,4);
    \draw[green] (3.5,3) rectangle (6.5,7.5);
    %上一句和這一句,可知:兩個座標高低沒有順序。
    \end{tikzpicture}
    \end{Example}
    
    \section{如何畫一個圓}
    \begin{Example}[frame=single]
    \begin{tikzpicture}
    \draw[black] (0,0) circle [radius=1cm];
    \draw[blue] (0,0) circle [radius=10pt];
    \draw[violet, fill=gray] (0,0) circle [radius=1ex];
    \end{tikzpicture}
    \end{Example}
    
    \subsection{畫圓另一個方法}
    \begin{Example}[frame=single]
    \begin{tikzpicture}
    \node[circle,draw,text=white,fill=lightgray] (c) at (0,0){Circle};
    \end{tikzpicture}
    \end{Example}
    
    \subsection{如何畫一個半徑為座標軸上2unit的圓}
    \begin{Example}[frame=single]
    \begin{tikzpicture}
    \draw[color=black, very thick] (1,0) circle (2);
    \draw[color=black!30, very thick] (10,0) circle (2);
    \end{tikzpicture}
    \end{Example}
    
    \subsection{如何畫一個半徑為1cm,顏色為橙色的圓}
    \begin{Example}[frame=single]
    \begin{tikzpicture}
    \draw[color=black!60, very thick, fill=orange](1,0) circle [radius=1];
    \draw[color=black!30, very thick] (2,0) circle (1);
    \node [circle, fill=olive,inner sep=1cm, text=white,%
    label=below:$X$] (X) at (10,0) {c1};
    \end{tikzpicture}
    \end{Example}
    
    
    \subsection{如何畫圓心是A、半徑是AB的圓}
    \usetikzlibrary {calc}
    \begin{Example}[frame=single]
    \begin{tikzpicture}
      \coordinate [label=left:$A$]  (A) at (3,3);
      \coordinate [label=right:$B$] (B) at (1.25,0.25);
      \draw (A) -- (B);
    % \p1是一個vector,座標是\x1, \y1,用veclen計算radius
      \draw (A) let
              \p1 = ($ (B) - (A) $)
            in
              circle ({veclen(\x1,\y1)});
    \end{tikzpicture}
    \end{Example}
    
    \section{如何畫一個橢圓}
    \begin{Example}[frame=single]
    \tikz \draw (0,0) ellipse [x radius=20pt, y radius=10pt];
    \end{Example}
    
    \section{如何畫X、Y座標軸}
    \begin{Example}[frame=single]
    \begin{tikzpicture}
      \draw[->]  (-1.5,0) -- (1.5,0) node[label=right:$x$]{};
      \draw[->]  (0,-1.5) -- (0,1.5) node[label=above:$y$]{};
      \draw (0,0) circle [radius=1cm];
    \end{tikzpicture}
    
    \begin{tikzpicture}
      \draw[->]  (-1.5,0) -- (1.5,0) node[right]{$x$};
      \draw[->]  (0,-1.5) -- (0,1.5) node[above]{$y$};
      \draw (0,0) circle [radius=1cm];
    \end{tikzpicture}
    \end{Example}
    
    \subsection{如何畫X、Y、Z座標軸}
    \begin{Example}[frame=single]
    \begin{tikzpicture}
      \draw[->]  (0,0,0) -- (1.5,0,0) node[label=right:$x$]{};
      \draw[->]  (0,0,0) -- (0,1.5,0) node[label=above:$y$]{};
      \draw[->]  (0,0,0) -- (0,0,2.5) node[label=above:$z$]{};
      \node[shape=circle, fill=gray, inner sep=1pt, %
      label=right:$X$] (X) at (0.5,0.5,0.5) {};
    \end{tikzpicture}
    \end{Example}
    
    \section{如何畫一段圓弧}
    \begin{Example}[frame=single]
    \begin{tikzpicture}[scale=3]
      \draw[step=.5cm,gray,very thin] (-1.4,-1.4) grid (1.4,1.4);
      \draw[->]  (-1.5,0) -- (1.5,0) node[label=right:$x$]{};
      \draw[->]  (0,-1.5) -- (0,1.5) node[label=above:$y$]{};
      \draw (0,0) circle[radius=1cm];
      \draw[fill=gray, opacity=0.5] (-0.5,0)--(0.5,0)  %
      arc [start angle=0, end angle=135, radius=1cm] -- (-0.5,0) ;
    \end{tikzpicture}
    \end{Example}
    
    \section{如何畫拋物線}
    \begin{Example}[frame=single]
    \begin{tikzpicture}[scale=3]
      \draw[step=.5cm,gray,very thin] (-1.4,-1.4) grid (1.4,1.4);
      \draw[->]  (-1.5,0) -- (1.5,0) node[label=right:$x$]{};
      \draw[->]  (0,-1.5) -- (0,1.5) node[label=above:$y$]{};
      \draw  (0,0) parabola (1,1);
      \draw (-0.5,-0.5) parabola bend (1,0.5) (1.4,0.4);
    \end{tikzpicture}
    \end{Example}
    
    %https://tikz.dev/dv-main
    \begin{Example}[frame=single]
    \usetikzlibrary {datavisualization.formats.functions}
    \begin{tikzpicture}
      \datavisualization [school book axes, visualize as smooth line]
    data [format=function] {
      var x : interval [-1.5:1.5] samples 10;
      func y = \value x*\value x;
    };
    \end{tikzpicture}
    \end{Example}
    
    \subsection{更多和拋物線有關的例子}
    \usepgfplotslibrary{fillbetween}
    \usetikzlibrary{patterns}
    \begin{Example}[frame=single]
    \pgfplotsset{compat=1.12}
    \begin{figure}[h]
      \centering
      \begin{tikzpicture}
    \begin{axis}[
        xmin=-1, xmax=3,
        ymin=-1, ymax=3,
        axis lines=middle,
      ]  
      \addplot[samples=100, domain=0:3, name path=A] {3/(2*x+1)}; 
      \addplot[samples=50, domain=0:3,name path=B] {3*x-2}; 
      \path[name path=xaxis] (\pgfkeysvalueof{/pgfplots/xmin}, 0)%
        -- (\pgfkeysvalueof{/pgfplots/xmax},0);
       \addplot[gray, pattern=north west lines] fill %
       between[of=B and xaxis, soft clip={domain=0.66666:1}];
      \addplot[gray, pattern=north west lines] fill %
      between[of=A and xaxis, soft clip={domain=1:2}];
      \addplot +[mark=none] coordinates {(2, -1) (2, 3)};
    \end{axis}
      \end{tikzpicture}
    \end{figure}
    \end{Example}
    這個例子摘錄,但我不理解。
    
    \begin{Example}[frame=single]
    \begin{tikzpicture}
    \draw[gray,very thin] (-1.9,-1.9) grid (2.9,3.9)
    [step=0.25cm] (-1,-1) grid (1,1);
    \draw[blue] (1,-2.1) -- (1,4.1); % asymptote
    \draw[->] (-2,0) -- (3,0) node[right] {$x(t)$};
    \draw[->] (0,-2) -- (0,4) node[above] {$y(t)$};
    \foreach \pos in {-1,2}
    \draw[shift={(\pos,0)}] (0pt,2pt) -- (0pt,-2pt) node[below] {$\pos$};
    \foreach \pos in {-1,1,2,3}
    \draw[shift={(0,\pos)}] (2pt,0pt) -- (-2pt,0pt) %
    node[left] {$\pos$};
    \fill (0,0) circle (0.064cm);
    \draw[thick,parametric,domain=0.01:5,samples=200]
    % The plot is reparameterised such that there are more samples
    % near the center.
    plot[id=asymptotic-example] function{(t)*sin(1/(t)),%
    (t)*cos(1/(t))}
    node[above right] %
    {$\bigl(x(t),y(t)\bigr) = (t\sin \frac{1}{t}, t\cos \frac{1}{t})$};
    \fill[red] (0.63662,0) circle (2pt)
    node [below right,fill=white,yshift=-4pt] %
    {$(\frac{2}{\pi},0)$};
    \end{tikzpicture}
    \end{Example}
    
    這個例子來自官方tikz manual文檔,但我不理解。
    
    \subsection{如何畫正弦、餘弦曲線}
    \begin{Example}[frame=single]
    \begin{tikzpicture}
      \draw[step=.5cm,gray,very thin] (-2,-2) grid (4,4);
      \draw[->]  (-2,0) -- (4,0) node[label=right:$x$]{};
      \draw[->]  (0,-2) -- (0,4) node[label=above:$y$]{};
      \draw (0,0) sin (1,1) cos (2,0) sin (3,-1) cos (4,0) ;
    
      \draw[blue] (-2,0) cos (-1,-1) ;
      \draw[violet,thick] (-1,-1) cos (0,0);
      
      \draw[red,thick] (-2,0) sin (-1,-1) ;
      \draw[yellow] (-1,-1) sin (0,0);
      
    \end{tikzpicture}
    \end{Example}
    
    %https://tex.stackexchange.com/questions/356488/add-a-vertical-line-to-tikzpicture-plot
    %\usetikzlibrary{arrows}
    %\usetikzlibrary{datavisualization.formats.functions}
    %\usepackage{pgfplots}  
    \begin{Example}[frame=single]
    \begin{tikzpicture}
    \datavisualization [school book axes,
    visualize as smooth line/.list={one,two,three},
    y axis={label={$u(t)$}},
    x axis={label={$t$}},
    one={style={black}},
    two={style={red}},
    three={style={orange}}]
    
    data [set=one,format=function] {
        var x : interval [-3:3];
        func y = sin((\value x) r );
    }
    
    data [set=two,format=function] {
        var x : interval [-3:3];
        func y = sin((1.5 - \value x) r);
    };
    
    \draw [dashed] (1.5,-1) -- (1.5,1);
    \end{tikzpicture}                       
    \end{Example}                        
    
    %https://tikz.dev/dv-main
    \usetikzlibrary {datavisualization.formats.functions}
    \begin{Example}[frame=single]
    \begin{tikzpicture}[baseline]
      \datavisualization [ scientific axes=clean,
                       y axis=grid,
                       visualize as smooth line/.list={sin,cos,tan},
                       style sheet=strong colors,
                       style sheet=vary dashing,
                       sin={label in legend={text=$\sin x$}},
                       cos={label in legend={text=$\cos x$}},
                       tan={label in legend={text=$\tan x$}},
                       data/format=function ]
      data [set=sin] {
    var x : interval [-0.5*pi:4];
    func y = sin(\value x r);
      }
      data [set=cos] {
    var x : interval [-0.5*pi:4];
    func y = cos(\value x r);
      }
      data [set=tan] {
    var x : interval [-0.3*pi:.3*pi];
    func y = tan(\value x r);
      };
    \end{tikzpicture}
    \end{Example}
                    
    \section{如何畫角}
    
    一根直線可以起名,這樣直線的交點可以用intersection定點。
    \usetikzlibrary {intersections} 
    \begin{Example}[frame=single]
    \begin{tikzpicture}[scale=3]
      \clip (-0.1,-0.2) rectangle (1.1,1.51);
      \draw[step=.5cm,gray,very thin] (-1.4,-1.4) grid (1.4,1.4);
      \draw[->] (-1.5,0) -- (1.5,0);
      \draw[->] (0,-1.5) -- (0,1.5);
      \draw (0,0) circle [radius=1cm];
      \filldraw[fill=green!20,draw=green!50!black] (0,0) -- (3mm,0mm)
        arc [start angle=0, end angle=30, radius=3mm] -- cycle;
      \draw[red,very thick]    (30:1cm) -- +(0,-0.5);
      \draw[blue,very thick]   (30:1cm) ++(0,-0.5) -- (0,0);
    
      \path [name path=upward line,draw] (1,0) -- (1,1);
      \path [name path=sloped line,draw] (0,0) -- (30:1.5cm);
      \draw [name intersections={of=upward line and sloped line, by=x}]
        [very thick,orange] (1,0) -- (x);
    \end{tikzpicture} 
    \end{Example}
    
    \subsection{如何畫角的指示,以及如何添加註釋文字}
    直線用直線上兩點命名,直線的交點intersection cs用first line、second line。
    \usetikzlibrary{angles, calc, quotes}
    \begin{Example}[frame=single]
    \begin{tikzpicture}[angle radius=.75cm]
    %請注意觀察A與B的差別
      \node[shape=circle,inner sep=2pt, fill=black!50,label=above:$A$]%
       (A) at (-2,0)  [red]   {};
      \node (B) at ( 3,.5)  %
      [shape=circle,inner sep=1pt, fill=black!50, text=black] {$B$};
      \node (C)   at (-2,2)     [blue,left]  {$C$};
      \node (D) at ( 3,2.5)   [blue,right] {$D$};
      \node (E) at (60:-5mm)  [below]      {$E$};
      \node (F) at (60:3.5cm) [above]      {$F$};
    \node[shape=circle, inner sep=1pt, fill=blue, label=-45:\tiny $x$]%
     (x) at (intersection cs:first line={(A)--(B)}, %
    second line={(E)--(F)}) {};
    \node[shape=circle, inner sep=1pt, fill=blue, label=20:\tiny $y$]%
     (y) at (intersection cs:first line={(C)--(D)}, %
     second line={(E)--(F)}){};
    
      \path
    (A) edge [red, thick]  (B)
    (C) edge [blue, thick] (D)
    (E) edge [thick]       (F)
      pic ["$\alpha$", draw, fill=yellow]   {angle = F--x--A}
      pic ["$\beta$",  draw, fill=green!30] {angle = B--x--F}
      pic ["$\gamma$", draw, fill=yellow]   {angle = E--y--D}
      pic ["$\delta$", draw, fill=green!30] {angle = C--y--E};
    
      \node at ($ (D)!.5!(B) $) [right=1cm,text width=6cm,%
      rounded corners, fill=red!20, inner sep=1ex]
    {
      When we assume that $\color{red}AB$ and $\color{blue}CD$ %
      are parallel, i.\,e., ${\color{red}AB} \mathbin{\|} %
      \color{blue}CD$,
      then $\alpha = \gamma$ and $\beta = \delta$.
    };
    \end{tikzpicture}
    \end{Example}
    
    \usetikzlibrary {angles}
    \begin{Example}[frame=single]
    \tikz \draw (2,0) coordinate (A) -- (0,0) coordinate (B)
         -- (-1,-1) coordinate (C)
           pic [fill=black!50]                      {angle = A--B--C}
           pic [draw,->,red,thick,angle radius=1cm] {angle = C--B--A};
           
    \end{Example}
    
    %Questioner: marmistrz, Answerer: rpapa, ``Create angle bisectors in TikZ'', \url{https://tex.stackexchange.com/questions/233246/create-angle-bisectors-in-tikz}
    \begin{Example}[frame=single]
    \usetikzlibrary {angles}
      \tikz
    \draw (0,0,0) coordinate (O)
      (1,0,0) coordinate (A) -- (O)
      (0,0,1) coordinate (B) -- (O)
      (0,1,0) coordinate (C) -- (O)
      pic [fill=gray,angle radius=4mm] {right angle = A--O--B}
      pic [draw,red,thick,angle eccentricity=.5,pic text=.]
        {right angle = A--O--C};
    \end{Example}
    
    \subsection{如何摘取一部分圖,放大}
    \begin{Example}[frame=single]
    \begin{tikzpicture}[scale=3]
     \clip (-0.1,-0.2) rectangle (1.1,1.51);
      \draw[step=.5cm,gray,very thin] (-1.4,-1.4) grid (1.4,1.4);
      \filldraw[fill=green!20,draw=green!50!black] (0,0) -- (3mm,0mm)
      arc [start angle=0, end angle=30, radius=3mm] -- cycle;
      \draw[->] (-1.5,0) -- (1.5,0);
      \draw[->] (0,-1.5) -- (0,1.5);
      \draw (0,0) circle [radius=1cm];
    
      \foreach \x in {-1cm,-0.5cm,1cm}
    \draw (\x,-1pt) -- (\x,1pt);
      \foreach \y in {-1cm,-0.5cm,0.5cm,1cm}
    \draw (-1pt,\y) -- (1pt,\y);
    \end{tikzpicture}
    \end{Example}
    
    \subsection{如何畫一個矩形}
    座標系左下角為(0,0)
    \begin{Example}[frame=single]
    \begin{tikzpicture}
    \draw[color=black, thick, fill=blue!80!white] (5,0) rectangle (10,1);
    \fill[blue!40!white] (0,0) rectangle (4,4);
    \fill[blue!60!red!90!green] (10,1) rectangle (12,4);
    \end{tikzpicture}
    \end{Example}
    
    \section{如何畫直線上某一位置的點}
    \subsection{如何畫AB中點}
    
    \begin{Example}[frame=single]
    \usetikzlibrary {calc}
    \begin{tikzpicture}
      \coordinate [label=left:$A$]  (A) at (0,0);
      \coordinate [label=right:$B$] (B) at (1.25,0.25);
      \draw (A) -- (B);
      \node [shape=circle, fill=red,inner sep=1pt,label=below:$X$]%
       (X) at ($ (A)!.5!(B) $) {};
    \end{tikzpicture}
    \end{Example}
    
    \subsection{如何畫底邊中線}
    %https://tikz.dev/math-parsing
    \begin{Example}[frame=single]
    \usetikzlibrary {calc,quotes}
    \tikz{
      \coordinate["$A$"]       (A) at (2,2);
      \coordinate["$B$" below] (B) at (0,0);
      \coordinate["$C$" below] (C) at (3,0);
      \draw (A) -- (B) -- (C) -- cycle;
      \path
    let \p1 =($(A)-(B)$), \p2 =($(A)-(C)$),
        \n1 = {veclen(\x1,\y1)}, \n2 = {veclen(\x2,\y2)}
    in  coordinate ["$D$" below] (D) at ($ (B)!0.5!(C) $);
      \draw (A) -- (D);
    }
    \end{Example}
    
    \subsection{如何畫出線段上某一比例的點}
    \begin{Example}[frame=single]
    \usetikzlibrary {calc,quotes}
    \tikz{
      \coordinate["$A$"]       (A) at (2,2);
      \coordinate["$B$" below] (B) at (0,0);
      \coordinate["$C$" below] (C) at (3,0);
      \draw (A) -- (B) -- (C) -- cycle;
      \path
    let \p1 =($(A)-(B)$), \p2 =($(A)-(C)$),
        \n1 = {veclen(\x1,\y1)}, \n2 = {veclen(\x2,\y2)}
    in  coordinate ["$D$" below] (D) at%
     ($ (B)!scalar(\n1/(\n1+\n2))!(C) $);
      \draw (A) -- (D);
    }
    \end{Example}
    
    \subsection{如何畫AB延長線上的距離A點3.5倍距離的一點C}
    \begin{Example}[frame=single]
    \usetikzlibrary {calc}
    \begin{tikzpicture}[redpoint/.style={shape=circle, %
    fill=red,inner sep=1pt}]
      \coordinate [redpoint, label=below:$A$]  (A) at (0,0);
      \coordinate [redpoint, label=below:$B$] (B) at (1.25,0.25);
      \draw (A) -- (B) ;
    
      \draw (A) -- ($ (A) ! 3.5 ! (B) $) coordinate %
       [redpoint,label=below:$C$] (C) ;
    \end{tikzpicture}
    \end{Example}
    
    \subsection{如何畫一個角,45度,一條邊是另一個條邊的兩倍長}
    
    \usetikzlibrary {calc,through}
    \begin{Example}[frame=single]
    \begin{tikzpicture}
      \coordinate [label=left:$A$]  (A) at (0,0);
      \coordinate [label=right:$B$] (B) at (0.75,0.25);
      \draw (A) -- (B);
      \coordinate [label=above:$D$] (D) at
    ($ (A) ! 2 ! 45:(B) $) {};
      \draw (A) --(D) --(B);
    \end{tikzpicture}  
    \end{Example}
    
    \subsection{如何畫一個正三角形}
    \usetikzlibrary {calc,through}
    \begin{Example}[frame=single]
    \begin{tikzpicture}
      \coordinate [label=left:$A$]  (A) at (0,0);
      \coordinate [label=right:$B$] (B) at (0.75,0.25);
      \draw (A) -- (B);
      \coordinate [label=above:$D$] (D) at
    ($ (A) ! 0.5 ! (B) ! sin(60)*2 ! 90:(B) $) {};
      \draw (A) --(D)--(B);
    \end{tikzpicture} 
    \end{Example}
    
    \subsection{一個複雜幾何圖例子}
    
    \usetikzlibrary {calc,intersections,through}
    \begin{Example}[frame=single]
    \begin{tikzpicture}[thick,help lines/.style={thin,draw=black!50}]
      \def\A{\textcolor{orange}{$A$}}   \def\B{\textcolor{input}{$B$}}
      \def\C{\textcolor{input}{$C$}}    \def\D{$D$}
      \def\E{$E$}                       \def\F{$F$}
      \def\G{$G$}                       \def\H{$H$}
      \def\K{$K$}                       \def\L{\textcolor{output}{$L$}}
    
      \colorlet{input}{blue!80!black}    \colorlet{output}{red!70!black}
    
      \coordinate [label=left:\A]  (A) at ($ (0,0) + .1*(rand,rand) $);
      \coordinate [label=right:\B] (B) at ($ (1,0.2) + .1*(rand,rand) $);
      \coordinate [label=above:\C] (C) at ($ (1,2) + .1*(rand,rand) $);
    
      \draw [input] (B) -- (C);
      \draw [help lines] (A) -- (B);
    
      \coordinate [label=above:\D] (D) at ($ (A)!.5!(B) ! {sin(60)*2} ! 90:(B) $);
    
      \draw [help lines] (D) -- ($ (D)!3.75!(A) $) coordinate [label=-135:\E] (E);
      \draw [help lines] (D) -- ($ (D)!3.75!(B) $) coordinate [label=-45:\F] (F);
    
      \node (H) at (B) [name path=H,help lines,circle through=(C),draw,label=135:\H] {};
      \path [name path=B--F] (B) -- (F);
      \path [name intersections={of=H and B--F,%
      by={[label=right:\G]G}}];
    
      \node (K) at (D) [name path=K,help lines,circle through=(G),draw,label=135:\K] {};
      \path [name path=A--E] (A) -- (E);
      \path [name intersections={of=K and A--E,%
      by={[label=below:\L]L}}];
    
      \draw [output] (A) -- (L);
    
      \foreach \point in {A,B,C,D,G,L}
    \fill [black,opacity=.5] (\point) circle (2pt);
    
      % \node ...
    \end{tikzpicture}
    \end{Example}
    
    
    
    
    
    \section{如何畫輔助線虛線}
    畫一個鈍角三角形,40度,一條邊是另一個條邊的3倍長。
    
    方法1
    \usetikzlibrary {calc,through}
    \begin{Example}[frame=single]
    \begin{tikzpicture}
      \coordinate [label=left:$A$]  (A) at (0,0);
      \coordinate [label=below:$B$] (B) at (1,0);
      \draw (A) -- (B);
      \coordinate [label=above:$C$] (C) at
    ($ (A) ! 3 ! 40:(B) $) {};
      \draw (A) --(C) --(B);
      \draw[dashed] (B) -- ($(A) ! 3!(B)$) coordinate (D);
      \coordinate (E) at ($(C)!1!50:(A)$);
      \coordinate[label=below:$F$] (F) at%
       (intersection cs:first line={(B)--(D)}, %
       second line={(C)--(E)});
      \draw[dashed]  (C) -- (F);
      \draw (F)++(0,3pt) -- ++(3pt,0pt) -- ++(0,-3pt);
    \end{tikzpicture} 
    \end{Example}
    
    方法2
    \usetikzlibrary {calc,through}
    \begin{Example}[frame=single]
    \begin{tikzpicture}
      \coordinate [label=left:$A$]  (A) at (0,0);
      \coordinate [label=below:$B$] (B) at (1,0);
      \draw (A) -- (B);
      \coordinate [label=above:$C$] (C) at
    ($ (A) ! 3 ! 40:(B) $) {};
      \draw (A) --(C);
      \draw (B) -- (C);
      % 畫AB的延長線,line1
      \draw[dashed] (B) -- ($(A) ! 3!(B)$) coordinate (Y);
      % 畫C向下垂直的線,line2
      \path (C) -- ++(-90:2) coordinate (X);
      \coordinate[label=below:$F$] (F) at%
       (intersection cs:first line={(C)--(X)}, %
       second line={(B)--(Y)});
      \draw[dashed] (C) -- (F);
      \draw (F)++(0,3pt) -- ++(3pt,0pt) -- ++(0,-3pt);
    \end{tikzpicture}
    \end{Example}
    
    方法3
    \usetikzlibrary {calc,through}
    \begin{Example}[frame=single]
    \begin{tikzpicture}
      \coordinate [label=left:$A$]  (A) at (0,0);
      \coordinate [label=below:$B$] (B) at (1,0);
      \draw (A) -- (B);
      \coordinate [label=above:$C$] (C) at (40:3);
      \draw (A) --(C);
      \draw (B) -- (C);
      % 畫AB的延長線,line1
      \draw[dashed, name path=line1] (B) -- %
      ($(A) ! 3!(B)$) coordinate (Y);
      % 畫C向下垂直的線,line2
      \path[name path=line2] (C) -- ++(-90:2) coordinate (X);
      \draw [name intersections={of=line1 and line2, by=F}]%
        [dashed] (C) -- (F) node[label=below:$F$]{};
      \draw (F)++(0,3pt) -- ++(3pt,0pt) -- ++(0,-3pt);
    \end{tikzpicture}
    \end{Example}
    
    方法4
    \usetikzlibrary {calc,through}
    \begin{Example}[frame=single]
    \begin{tikzpicture}
      \coordinate [label=left:$A$]  (A) at (0,0);
      \coordinate [label=below:$B$] (B) at (1,0);
      \coordinate [label=above:$C$] (C) at (40:3);
      \draw (A) -- (B) --(C) --cycle;
      %C在AB上的投影點
      \coordinate [label=below:$F$] (F) at ($(A)!(C)!(B)$);
      % 畫AB的延長線,line1
      \draw[dashed, name path=line1] (B) -- ($(A) ! 3!(B)$) %
      coordinate (Y);
      \draw[dashed, name path=line2] (C) --(F);
      \draw (F)++(0,3pt) -- ++(3pt,0pt) -- ++(0,-3pt);
    \end{tikzpicture}
    \end{Example}
    
    結論:方法4最好,Tikz可以在一條線段上畫出某一點的投影點,即垂線的垂足。
    
    \section{如何畫角平分線}
    \begin{Example}[frame=single]
    \usetikzlibrary{positioning,calc,intersections}
    \begin{tikzpicture}
    \coordinate[label=below left:$C$](C) at (-2,0);
    \coordinate[label=below right:$A$](A) at (8,0);
    \coordinate[label=above left:$B$] (B) at (0,7);
    \coordinate[label=above right:$D$](D) at ($(A)!(C)!(B)$);
    
    %  first name the path
    \draw[name path=t1] (A) -- (B) -- (C) -- cycle;
    \draw[name path=CD] (C) -- (D);
    
    % draw circle
    \path[name path=c1] (B) circle (2);
    % name intersection
    \path [name intersections={of = c1 and t1, by={x,y}}];
    % draw line beetwen intersections
    \path (x)--(y);
    % draw the bissector
    \path[name path=bissec] (B) -- ($(x)!0.5!(y)$) coordinate[pos=3](e)--(e);
    \path [name intersections={of = CD and bissec, by=F}];
    
    \draw[thick,red] (B) --(F);
    \end{tikzpicture}
    \end{Example}
    
    \subsection{角平分線舉例}
    已知$AD$、$AE$分別是$\triangle ABC$的角$A$的內、外角平分線,點$D$在邊$BC$上,點$E$在邊$BC$上的延長線上。求證:$\displaystyle \frac{1}{BE}+\frac{1}{CE}=\frac{2}{DE}$。
    \usetikzlibrary{positioning,calc,intersections}
    \begin{Example}[frame=single]
    \begin{figure}[h!]
    \centering
    \begin{tikzpicture}
    \coordinate[label=below:$B$] (B) at (0,0);
    \coordinate[label=45:$C$] (C) at (3,0);
    \coordinate[label=above:$A$] (A) at (35:5);
    \draw[name path=t1] (B)--(C)--(A)--cycle;
    
    % start drawing 1st angle bisection
    \path[name path=c1] (A) circle (1);
    % name intersections
    \path[name intersections = {of = t1 and c1, by={x, y}}];
    % draw angle bisection
    \coordinate (z) at ($(x)!.5!(y)$) ;
    \coordinate (u) at ($(A) !3.4! (z)$);
    % Intersection of angle bisection and the edge
    \coordinate[label=below:$D$] (D) at (intersection cs:first line={(A)--(u)}, second line={(B)--(C)});
    \draw (A)--(D);
    \draw pic[draw, angle radius = 0.5cm] {angle = B--A--D};
    \draw pic[draw, angle radius = 0.6cm] {angle = D--A--C};
    
    %start drawing 2nd angle bisection
    \coordinate[label=above:$P$] (P) at ($(B)!1.6!(A)$);
    \draw[dashed] (A)--(P);
    
    \coordinate (v) at ($(B)!3.1!(C)$);
    \draw[name path=e1] (C)--(v);
    
    \path[name path=b2] (A) -- ($(A)!3!90:(D)$);
    \path[name intersections = {of = e1 and b2, by = w}];
    \coordinate[label=below:$E$] (E) at (w);
    \draw (A) -- (E);
    \draw pic[draw,double, angle radius = 0.5cm] {angle = C--A--E};
    \draw pic[draw,double, angle radius = 0.6cm] {angle = E--A--P};
    
    % Help lines
    \coordinate[label=above:$F$] (F) at ($(A)!(D)!(B)$);
    \draw[dashed] (D) -- (F);
    \draw pic[draw, angle radius = 0.2cm] {right angle = D--F--A};
    
    \coordinate[label=below:$G$] (G) at ($(A)!(D)!(C)$);
    \draw[dashed] (D) -- (G) -- (C);
    \draw pic[draw, angle radius = 0.2cm] {right angle = D--G--A};
    
    \coordinate[label=below:$H$] (H) at ($(A)!(E)!(C)$);
    \draw[dashed] (E) -- (H) ;
    \draw pic[draw, angle radius = 0.2cm] {right angle = E--H--A};
    
    \coordinate[label=above:$I$] (I) at ($(A)!(E)!(P)$);
    \draw[dashed] (E) -- (I) ;
    \draw pic[draw, angle radius = 0.2cm] {right angle = E--I--A};
    \end{tikzpicture}
    \end{figure}
    \end{Example}
    
    證明:
    
    思路:$DE = BE - BD$,$DE = DC + CE$,所以$\displaystyle \frac{1}{BE}+\frac{1}{CE}=\frac{2}{DE}$可化為$\displaystyle \frac{BD}{BE} = \frac{DC}{CE}$(目標公式)。角平分線的點畫垂線可得到全等直角三角形。\
    
    添加輔助線,通過$D$向$AB$、$AC$畫垂線,分別為$DF$、$DG$,$DF = DG$;通過$E$向$AC$、$AP$畫垂線,分別為$EH$、$EI$,$EH = EI$。因為角平分線,可知\
    
     $\because \triangle BDF\usim \triangle BEI$ \
    
     $\displaystyle \therefore \frac{BD}{BE} = \frac{DF}{EI}$\
    
    $\because \triangle DGC\usim \triangle BHC$ \
    
     $\displaystyle \therefore \frac{DC}{CE} = \frac{DG}{EH}$\
     
    故, $\displaystyle  \frac{BD}{BE} = \frac{DC}{CE}$,得到目標公式。證畢。
    
    \begin{thebibliography}{99}
    \bibitem{hdzw}
    厚德载物,``tikz绘制的全等与相似符号'',2022-07-25,\url{https://www.latexstudio.net/index/details/index/mid/2816.html}
    \end{thebibliography}
    
    
    \end{document}
    
    
    
    
    bash
![](https://ad.itadn.com/c/weblog/blog-img/images/2025-08-15/0rVaJoQ4jdiL9f8I6q52hMXSBpkR.png)

全部评论 (0)

还没有任何评论哟~