如何用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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值