坐标


绘制都是在画布上进行的,它的左下角为原点。所以坐标指的就是画布上的一个点。 在tikz中一个坐标的语法是

([选项,选项,...]坐标规范)
通过“坐标规范”,可以使用许多不同的坐标系统,“选项”一般是坐标变换。 坐标系统可以是显式的,比如
(canvas cs:x=0cm,y=2mm)
明确指定了使用画布坐标系统。明确指定坐标系统的办法是
(坐标系统的名字 cs:键=值,键=值,...)
坐标系统也可以是隐含的,比如
(0cm,2mm)
隐含地使用了画布坐标系统。

画布(canvas)坐标系统

画布坐标系统的名字是“canvas”,它的两个键分别是“x”和“y”,值可以是任意 有效的TeX长度表示(带长度单位)。比如

(canvas cs:x=2cm,y=-5mm+2pt)

你也可以隐含地使用画布坐标系统,办法是

(横坐标,纵坐标)
当然,要带长度单位。比如
(0cm,3pt)

xyz坐标系统

xyz坐标系统的名字是“xyz”,它的三个键分别是“x”、“y”和“z”,值不带 长度单位,缺省情况下,“x”向量向右1cm,“y”向上1cm,“z”向量指向 (-1/sqrt(2)cm,-1/sqrt(2)cm)。比如

(xyz cs:x=1)

你还可以隐含地使用xyz坐标系统,比如

(1,0)
或者
(0,0,1)
注意:都没有带长度单位。

画布极坐标(canvas polar)系统

画布极坐标系统的名字是“canvas polar”,它有四个键:“angle”、“radius”、 “x radius”、“y radius”。“angle”必须在-360到720之间。如果只有一个“radius”,表示圆,如果既有“x radius”, 又有“y radius”,则表示椭圆。比如

(canvas polar cs:angle=30,radius=1cm)

画布极坐标的隐含形式是角度与半径间用冒号分隔,半径要带长度单位,比如

(30:1cm)

xyz极坐标(xyz polar)系统

xyz极坐标系统的名字是“xyz polar”,它和画布坐标系统的区别就是半径不带长度单位。 比如

(xyz polar cs:angle=0,radius=1)
(150:1)

xy极坐标(xy polar)系统

xy极坐标其实就是xyz极坐标的别名。

barycentric坐标系统

barycentric坐标系统的名字是“barycentric”,它将系统中的一个点表示为多个向量的线性组合

{a_1v_1+a_2v_2+...+a_nv_n}/{a_1 + a_2 + ... + a_n}
其中v_i表示第i个向量,a_i表示第i个系数。你可以非常容易地指定这样的坐标。

下面的例子中,向量就是三个节点的锚定,三个数字分别是“content”、“structure”、 “form”的值

\begin{tikzpicture}
\coordinate (content) at (90:3cm);
\coordinate (structure) at (210:3cm);
\coordinate (form) at (-30:3cm);
\node [above] at (content) {content oriented};
\node [below left] at (structure) {structure oriented};
\node [below right] at (form) {form oriented};
\draw [thick,gray] (content.south) -- (structure.north east) -- (form.north west) -- cycle;
\small
\node at (barycentric cs:content=0.5,structure=0.1 ,form=1) {PostScript};
\node at (barycentric cs:content=1 ,structure=0 ,form=0.4) {DVI};
\node at (barycentric cs:content=0.5,structure=0.5 ,form=1) {PDF};
\end{tikzpicture}

节点坐标系统

节点坐标系统的名字是“node”,它的键分别是

name 节点的名字,你可以通过名字引用一个节点
anchor 指定锚定点,也就是连接线与节点上的哪一个点相连,这与节点的形状有关
angle 如果不用锚定点,用角度也可以指定连接点
比如
\begin{tikzpicture}
\node (start) [draw,shape=ellipse] {start};
\foreach \angle in {-90, -80, ..., 90}
\draw (node cs:name=start,angle=\angle)
.. controls +(\angle:1cm) and +(-1,0) .. (2.5,0);
\end{tikzpicture}

节点坐标系统的隐含语法就是在坐标中使用坐标的名字。

正切(tangent)坐标系统

正切坐标系统的名字是“tangent”,它的键分别是

node 指定了tangent切于哪一个节点的边界上
point 指定tangent通过哪一点
solution 如果多个方案应该用哪一个
为了使用正切坐标系统,必须加载“calc”包
\usetikzlibrary{calc}
比如
\begin{tikzpicture}
\draw[help lines] (0,0) grid (3,2);
\coordinate (a) at (3,2);
\node [circle,draw] (c) at (1,1) [minimum size=40pt] {$c$};
\draw[red] (a) -- (tangent cs:node=c,point={(a)},solution=1) --
(c.center) -- (tangent cs:node=c,point={(a)},solution=2) -- cycle;

交叉点坐标

在tikz中可以方便地表示交点的坐标。其中最简单的就是垂直相交线的交点,你可以在选项中 使用下列键表示交点

horizontal line through={(坐标)}
vertical line through={(坐标)}
但更方便的是它的简洁形式
(p |- q)
(p -| q)
比如
(2,1 |- 3,4)
(3,4 -| 2,1)

任意路径的交点需要用“intersections”库

\usetikzlibrary{intersections}
它提供了下列选项来表示路径交点
name path=路径名字
name intersections={选项}
of=路径名1 and 路径名2
name=交叉点节点名字的前缀
total=存放交点总数的寄存器的名字
by={交点坐标名字1,交点坐标名字2,...}
sort by=路径名字
比如
\begin{tikzpicture}
\clip (-2,-2) rectangle (2,2);
\draw [name path=curve 1] (-2,-1) .. controls (8,-1) and (-8,1) .. (2,1);
\draw [name path=curve 2] (-1,-2) .. controls (-1,8) and (1,-8) .. (1,2);
\fill [name intersections={of=curve 1 and curve 2, name=i, total=\t}]
[red, opacity=0.5, every node/.style={above left, black, opacity=1}]
\foreach \s in {1,...,\t}{(i-\s) circle (2pt) node {\footnotesize\s}};
\end{tikzpicture}

相对坐标

在坐标前添加“+”号可使其成为相对坐标,比如

++(1cm,0pt)
表示相对于前一个点,也就是前一个点的坐标,加上“(1cm,0pt)”才是真正的坐标。

你也可以只用一个“+”号,比如

++(1,0)
它不会修改当前坐标,其实就是相对于其“初始”坐标。


目录