Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SVG path commands "s" and "t"

Tags:

svg

When implementing "s" (relative cubic Bezier arc) and "t" (relative quadratic Bezier arc) commands are the coordinates of the implicitly defined control point used as base for next relative coordinate or not?

In other words consider the following cubic arc:

cubic arc example

  • cp current point
  • ip implicit control point computed mirroring last control point from previous arc
  • ep explicit control point
  • fp final point of the arc

Should be the relative coordinates of ep use as base ip (the implicit point) or should they be relative to cp (the current point of the path)?

In the official documentation I found this unclear and no example using relative coordinates in these cases.

like image 358
6502 Avatar asked Apr 07 '13 08:04

6502


1 Answers

The rules are

  1. When using relative mode the coordinates are relative to the current point at the start of the command

  2. In case of a command "chain" when multiple coordinates are given without repeating the command the base point is updated after each repetition

For example the simple path

m 100,100 100,0 0,100 -100,0 0,-100

describes a square from (100,100) to (200,200)

simple relative path

(the l "line-to" command shown in red is implicit if multiple coordinates pairs are provided for a "m" command)

The important point to note is that the relative "base" for coordinates is updated at each turning point. This is somewhat deceiving in the documentation because the syntax of m command is described as accepting (x,y)+ as parameter so the reader could be tricked into thinking that the relative base will change only at the end of the entire sequence of points.

Now let's consider the Bezier cubic path

m 100,100 c 25,25 75,25 100,0 s 25,125 0,100 -75,-25 -100,0

bezier arcs example

The two red control points are computed automatically by mirroring the last control point. The red s command is implicit because four points followed s.

For a cubic Bezier arc command the two control points and the end point are relative to the same start point (they're not relative to the previous in sequence) but at each arc the base point for relative coordinate computation is updated.

like image 93
6502 Avatar answered Sep 22 '22 00:09

6502