关闭 SVG 路径时 "z" 和 "Z" 有什么区别?

What is the difference of "z" and "Z" when closing an SVG path?

创建SVG路径时,通常d attribute中的大写字母(ML...)指的是绝对坐标,小写字母(m, l...) 指的是到最后一点的相对坐标。

下面是一个在绝对坐标下绘制小直角三角形的例子:

<path style="stroke:black;fill:none;" d="M100,100 L150,100 V50 Z" />

这会在相对坐标中绘制相同的三角形:

<path style="stroke:black;fill:none;" d="m100,100 l50,0 v-50 z" />

我可以使用大写或小写 MZ,在任何一种情况下,视觉上都没有任何变化。关于M,我假设因为是第一个点,所以是相对于(0, 0)的绝对值或者相对值,如有不妥请指正。 zZ有什么区别?

zZ都定义了Path CommandClosePath


Path commands are instructions that define a path to be drawn. Each command is composed of a command letter and numbers that represent the command parameters.

SVG defines 6 types of path commands, for a total of 20 commands:

  • MoveTo: M, m
  • LineTo: L, l, H, h, V, v
  • Cubic Bézier Curve: C, c, S, s
  • Quadratic Bézier Curve: Q, q, T, t
  • Elliptical Arc Curve: A, a
  • ClosePath: Z, z

在所有情况下:

An upper-case command specifies absolute coordinates, while a lower-case command specifies coordinates relative to the current position. path_commands

但是在z/Z的情况下没有区别(ClosePath)。 z/Z 没有绝对或相对坐标,所以它只会在最后一点和起点之间创建一条直线。