下面一個例子展示如何使用Tikz完成:
- 定義一個坐標點,以備后面畫線時直接使用窍奋;
- 定義一個極坐標點荐健,以備在圓上快速定點;
- 根據(jù)定義的點進行路徑的定義费变;
- 根據(jù)定義的路徑計算路徑的交點摧扇;
- 根據(jù)定義的坐標點進行封閉區(qū)域/形狀的旋轉(zhuǎn)!
注意:以上的所有操作不需要額外導(dǎo)入Tikz中的其他庫挚歧,直接導(dǎo)入\usepackages{tikz}就可以實現(xiàn)上面的各種功能。
% 極坐標定點示例:長度不帶單位吁峻,默認坐標單位一樣滑负! —— 方便!
% 極坐標更方便的一點:代碼改動杏煤矮慕!只用調(diào)角度即可!
\begin{figure}[H]
\centering
\begin{tikzpicture}[scale = 3]
%\draw [thick, <->] (-2,2.5) node [left] {$x_2$} -- (-2,-2) -- (2.5,-2) node [below right] {$x_1$};
\draw (0,0) circle [radius = 1]; % 注意:為了普通坐標和極坐標可以通用啄骇,把圓心定在原點痴鳄!
% 第一個三角形:
\coordinate (O) at (0:0); % 原點
\coordinate (A) at (90:1);
\coordinate (B) at (210:1);
\coordinate (C) at (-30:1);
\draw [red] (A) -- (B) -- (C) -- (A);
% 第二個三角形:
\coordinate (D) at (-90:1);
\coordinate (E) at (30:1);
\coordinate (F) at (150:1);
\draw [green] (D) -- (E) -- (F) -- (D);
% 定義路徑:不畫出來
\path [name path = AB] (A) -- (B); \path [name path = AC] (A) -- (C); \path [name path = BC] (B) -- (C);
\path [name path = DE] (D) -- (E); \path [name path = DF] (D) -- (F); \path [name path = EF] (E) -- (F);
% 算交點:不畫出來
\path [ name intersections = {of = AB and EF, by = i1} ];
\path [ name intersections = {of = AB and DF, by = i2} ];
\path [ name intersections = {of = AC and EF, by = i3} ];
\path [ name intersections = {of = AC and DE, by = i4} ];
\path [ name intersections = {of = BC and DF, by = i5} ];
\path [ name intersections = {of = BC and DE, by = i6} ];
% 填充:
%\draw [very thin, fill = green, opacity = 0.5] (A) -- (i1) -- (i3) -- (A);
\draw [very thin, fill = green, opacity = 0.5] (E) -- (i3) -- (i4) -- (E);
%\draw [very thin, fill = green, opacity = 0.5] (C) -- (i4) -- (i6) -- (C);
\draw [very thin, fill = green, opacity = 0.5] (D) -- (i5) -- (i6) -- (D);
%\draw [very thin, fill = green, opacity = 0.5] (B) -- (i2) -- (i5) -- (B);
\draw [very thin, fill = green, opacity = 0.5] (F) -- (i1) -- (i2) -- (F);
% 旋轉(zhuǎn)一個圖形:在scope環(huán)境中
\begin{scope}[rotate around={33:(O)}]
% 坐標需要重定一遍
\coordinate (A1) at (90:1);
\coordinate (B1) at (210:1);
\coordinate (C1) at (-30:1);
\draw[blue] (A1) -- (B1) -- (C1) -- cycle; % cycle寫最后表示閉環(huán)
\end{scope}
\end{tikzpicture}
\caption{定義點+極坐標點、路徑缸夹、交點痪寻、旋轉(zhuǎn)}
\end{figure}
效果如下:
效果圖