[Latex]PGF and TiKz中let操作命令的使用

[Latex]PGF and TiKz中let操作命令的使用,还是看例子吧:

使用TIKZ中的函数,必须在frame 中添加选线[fragile],否则无法识别数学命令

\documentclass{beamer}
%====================================================
\input{../setup/preamble.tex}  
\input{../setup/tikzall.tex} %包含所有的tikz包
%====================================================
\begin{document}
%%====================================================
%\begin{frame}
%====================================================
\begin{frame}[fragile]
%演示let命令的用法
%以p开头的表示点point,以后可以使用\x和\y来引用其x坐标和y坐标
%已n开头的表示数字number
\begin{tikzpicture}[line width=1.2pt]
%绘制圆的切线
\draw [dashed,thin] (0,0) grid (8,4);
\coordinate (a) at (rnd,rnd); %随机的任意点
\coordinate (b) at (3-rnd,3-rnd);%随机的任意点
\draw (a) -- (b);
\node (c) at (1,2) {X};
\draw let \p1 = ($ (a)!(c)!(b) - (c) $),%过(c)点做ab的垂线,然后求垂足到c点的距离
\n1 = {veclen(\x1,\y1)}
in circle [at=(c), radius=\n1];
%绘制内交圆
\tikzset{xshift=5cm,yshift =2cm}
\coordinate [label=left:$A$] (A) at (0,0);
\coordinate [label=right:$B$] (B) at (1.25,0.25);
\draw (A) -- (B);
\draw let \p2 = ($ (B) - (A) $),
\n2 = {veclen(\x2,\y2)}
in
(A) circle (\n2)
(B) circle (\n2);
%---------------------------------------------------
%有时希望使用let对\p所指定的位置起个名字可以使用\p{nametext}
%\path % let's define some points:
%let
%\p3 = (1,0),
%\p4 = (3,2),
%\p{center} = ($ (\p1) !.5! (\p2) $) % center
%in
%coordinate (p1) at (\p1)
%coordinate (p2) at (\p2)
%coordinate (center) at (\p{center});%AB的中点
%\draw (p1) -- (p2);
%\fill[red] (center) circle [radius=3pt];
%---------------------------------------------------
%下面的用法也行的
\path % let's define some points:
let
\p{center} = ($ (A) !.5! (B) $) %AB的中点
in
coordinate (center) at (\p{center});
\fill[red] (center) circle [radius=3pt];
\end{tikzpicture}
\end{frame}
%====================================================
\end{document} 
效果如下

[Latex]PGF and TiKz中let操作命令的使用_第1张图片

你可能感兴趣的:([Latex]PGF and TiKz中let操作命令的使用)