PGF和tikz中如何定义一个实数

使用\pgfmathsetmacro,定义的实数在tikz的绘图环境中可以很方便的进行四则运算:

看下面的例子:

%传热学图4-3
\begin{tikzpicture}[>=stealth,line width=0.5pt] 
\useasboundingbox(0,-0.4)rectangle(5.25,5);
\coordinate  (P)at (2.5,2.5);
%%题注
\path (P)+(-0.8,-2.5) coordinate[label=0:{图$4-3$}];
%%画花括号:
\draw (P)+(0.5,+2.1) node[yscale=1,xscale=2.6,rotate=-90]{\{} ;
\draw (P)+(0.5,+2.1) coordinate[label=above:{\scriptsize $ \Delta x$}] ;
\draw (P)+(2.1,-0.5) node[yscale=2.6,xscale=1]{\}} ;
\draw (P)+(2.1,-0.5) coordinate[label=right:{\scriptsize $ \Delta y$}] ;
%
\clip[draw] (P) circle (2.0);
\foreach \i in {0.5,1.5,...,4.5}{
\draw(\i,0)--(\i,5);
}
\foreach \i in {0.5,1.5,...,4.5}{
\draw(0,\i)--(5,\i);
}
%矩形四个顶点坐标点

%绘制节点
\foreach \i in {0.5,1.5,...,4.5}{
	\foreach \j in {0.5,1.5,...,4.5}{
		\draw[fill](\i,\j)circle(0.75pt);
	}
}
\pgfmathsetmacro{\a}{0.1} 
\pgfmathsetmacro{\s}{0.5} 
%
\draw[fill=blue] (P) circle (2pt);
\draw[fill=red] (P)+(1,0) circle (2pt);
\draw[fill=red] (P)+(-1,0) circle (2pt);
\draw[fill=red] (P)+(0,1) circle (2pt);
\draw[fill=red] (P)+(0,-1) circle (2pt);
\path (P)+(0,-0.25 ) node[blue,scale=1](mn){$(m\text{,}n)$};
\path (P)+(-0.65,\a ) node[scale=\s](w){$w$};
\path (P)+(\a,-0.65 ) node[scale=\s](s){$s$};
\path (P)+(+0.65,\a ) node[scale=\s](e){$e$};
\path (P)+(\a,+0.65 ) node[scale=\s](n){$n$};
%
\pgfmathsetmacro{\b}{0.5} 
\pgfmathsetmacro{\c}{0.2} 
\path (P)+(\b,1+\c ) node[scale=\s](mn1){$(m\text{,}n+1)$};
\path (P)+(\b,-1-\c ) node[scale=\s](mn2){$(m\text{,}n-1)$};
\path (P)+(-1-\b,\c ) node[scale=\s](mn3){$(m-1\text{,}n)$};
\path (P)+(+1+\b,\c ) node[scale=\s](mn4){$(m+1\text{,}n)$};
%xelatex不支持pattern模式
\draw[dashed,pattern=north east  lines] (2.0,2.0) rectangle (3.0,3.0);
\end{tikzpicture} 
上面的例子使用pdflatex编译两次即可.图形如下:


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值