我的TikZ使用笔记。
TikZ Hello World
TikZ是PGF(Portable Graphic Format)的前端,其名称来源于德语TikZ ist kein Zeichenprogramm,意为TikZ is not a drawing program,是一个GNU’s Not Unix形式的递归缩写。
绘图模板
\documentclass[border=2pt]{standalone}
% Drawing
\usepackage{tikz}
\usepackage{tikz-3dplot}
% Styles
\tikzset{>=latex}
\begin{document}
\tdplotsetmaincoords{70}{110}
\begin{tikzpicture}[tdplot_main_coords]
% Plot Here
\end{tikzpicture}
\end{document}
宏定义
变量
%% Parameter Setup
% Translation World->A
\pgfmathsetmacro{\ax}{-0.5}
\pgfmathsetmacro{\ay}{1}
\pgfmathsetmacro{\az}{2.5}
% Translation World->B
\pgfmathsetmacro{\bx}{-1.5}
\pgfmathsetmacro{\by}{3.5}
\pgfmathsetmacro{\bz}{1}
% Euler Angle World->A
\pgfmathsetmacro{\rollWA}{0}
\pgfmathsetmacro{\pitchWA}{0}
\pgfmathsetmacro{\yawWA}{10}
% Euler Angle World->B
\pgfmathsetmacro{\rollWB}{0}
\pgfmathsetmacro{\pitchWB}{0}
\pgfmathsetmacro{\yawWB}{30}
% P_{W}
\pgfmathsetmacro{\px}{2}
\pgfmathsetmacro{\py}{4}
\pgfmathsetmacro{\pz}{5}
% Control Points
\pgfmathsetmacro{\mx}{(\ax + \bx) / 2}
\pgfmathsetmacro{\my}{(\ay + \by) / 2}
\pgfmathsetmacro{\mz}{(\az + \bz) / 2}
坐标系原点
%% Define Points
\coordinate (World) at (0, 0, 0);
\coordinate (A) at (\ax, \ay, \az);
\coordinate (B) at (\bx, \by, \bz);
\coordinate (P) at (\px, \py, \pz);
绘图命令
点、线段和曲线
%% Plot Point P
\fill[black] (P) circle[radius = 1pt];
\draw[thin, color = black, dashed] (A) -- (P) node[anchor = south east]{$\mathbf{P}_{\mathcal{A}}$};
\draw[thin, color = black, dashed] (B) -- (P) node[anchor = north west]{$\mathbf{P}_{\mathcal{B}}$};
%% Plot Poses
\draw[thin, color = black, ->] (World) sin (A);
\draw[thin, color = black, ->] (World) sin (B);
\draw[thin, color = black, ->] (A) parabola (B);
坐标系
%% Plot World Coordinates
\draw (World) node[anchor = south east]{$\left\{\mathcal{W}\right\}$};
\draw[thick, color = black, ->] (World) -- (1, 0, 0) node[anchor = east]{$x_{\mathcal{W}}$};
\draw[thick, color = black, ->] (World) -- (0, 1, 0) node[anchor = west]{$y_{\mathcal{W}}$};
\draw[thick, color = black, ->] (World) -- (0, 0, 1) node[anchor = south]{$z_{\mathcal{W}}$};
%% Plot A Coordinates
\tdplotsetrotatedcoords{\rollWA}{\pitchWA}{\yawWA}
\tdplotsetrotatedcoordsorigin{(A)}
\draw (A) node[anchor = south east]{$\left\{\mathcal{A}\right\}$};
\draw[thick, color = red, tdplot_rotated_coords, ->] (0, 0, 0) -- (1, 0, 0) node[anchor = north]{$x_{\mathcal{A}}$};
\draw[thick, color = green, tdplot_rotated_coords, ->] (0, 0, 0) -- (0, 1, 0) node[anchor = west]{$y_{\mathcal{A}}$};
\draw[thick, color = blue, tdplot_rotated_coords, ->] (0, 0, 0) -- (0, 0, 1) node[anchor = south]{$z_{\mathcal{A}}$};
%% Plot B Coordinates
\tdplotsetrotatedcoords{\rollWB}{\pitchWB}{\yawWB}
\tdplotsetrotatedcoordsorigin{(B)}
\draw (B) node[anchor = south west]{$\left\{\mathcal{B}\right\}$};
\draw[thick, color = red, tdplot_rotated_coords, ->] (0, 0, 0) -- (1, 0, 0) node[anchor = north]{$x_{\mathcal{B}}$};
\draw[thick, color = green, tdplot_rotated_coords, ->] (0, 0, 0) -- (0, 1, 0) node[anchor = west]{$y_{\mathcal{B}}$};
\draw[thick, color = blue, tdplot_rotated_coords, ->] (0, 0, 0) -- (0, 0, 1) node[anchor = south]{$z_{\mathcal{B}}$};
文字说明
%% Add Description
\draw (\ax / 2, \ay / 2, \az / 2) node[anchor = west] {$\mathbf{T}^{\mathcal{W}}_{\mathcal{A}}$};
\draw (\bx / 2, \by / 2, \bz / 2) node[anchor = west] {$\mathbf{T}^{\mathcal{W}}_{\mathcal{B}}$};
\draw (\mx, \my, \mz) node[anchor = east] {$\mathbf{T}^{\mathcal{A}}_{\mathcal{B}}$};
模板和学习资源查询
网站
教程
宏包文档
示例
- HarisIqbal88/PlotNeuralNet
- synercys/annotated_latex_equations
- xinychen/awesome-latex-drawing
- PetarV-/TikZ
- MLNLP-World/Paper-Picture-Writing-Code
- jluttine/tikz-bayesnet
- hackl/tikz-network
- hackl/TikZ-StructuralAnalysis
- cfiandra/timeline
- moepinet/moeptikz
- jellespijker/PIDcircuitTikZ
- fruchart/tikz-optics
- appliedcategorytheory/TikZWD
- LIAMF-USP/TikzTemplates
- hoganbin/TikZ-Learning-Notes
- AlexTsagas/Tikz-Graphics