tikz有绝对坐标和相对坐标两种,在定义坐标点一文用的是绝对坐标。相对坐标有两种表示方式,++和+。
在介绍++和+的区别之前,需要先介绍current point的概念。
以\draw (A) – (B) (C) – (D) 为例,首先把画笔移动到A点,此时current point为A;然后–(B),就画直线到B点,此时current point就是B点。然后到C点,因为B和C之间没有–,所以不会从B到C画线段;画笔直接移动到C点,此时current point为C;然后是画C到D的线段,并且current point是D点。
在这个过程中,current point是一直变化的。
相对坐标的++和+的区别就在于前者会改变current point,后者不会改变current point。
这里仍以画正六边形为例,对应http://blog.youkuaiyun.com/u013344915/article/details/51702502一文中的P1~P6一周,并分别用++和+表示。
方式一:改变current point的++语法
\draw (1,0)node [right]{P1}
--++(120:1cm)node [above right]{P2}
--++(-1,0)node [above left]{P3}
--++(240:1cm)node [left]{P4}
--++(300:1cm)node [below left]{P5}
--++(1,0)node [below right]{P6}
--cycle;
方式二:改变current point的++语法
\draw (1,0)node [right]{P1}
--+(120:1cm)node [above right]{P2}
--+(150:1.732cm)node [above left]{P3}
--+(-2,0)node [left]{P4}
--+(210:1.732cm)node [below left]{P5}
--+(240:1cm)node [below right]{P6}
--cycle;
下面是一个较为简单的例子:
\begin{tikzpicture}[scale=1]
\draw (0,0)node[below left]{A}--++(1,0)node[below right]{B}
--++(0,1)node[above right]{C}--++(-1,0)node[above left]{D}--cycle;
\draw (4,0)node[below]{A}--+(1,0)node[below right]{B}
--+(0,1)node[above right]{C}--+(-1,0)node[below left]{D}--cycle;
\end{tikzpicture}
图形: