Published by Patrick Mutisya · 14 days ago
Show understanding of how data for a vector graphic are encoded.
A vector graphic represents images using geometric primitives such as points, lines, curves and shapes defined by mathematical equations, rather than a fixed grid of pixels. This allows the image to be scaled without loss of quality.
Each primitive is stored as a sequence of commands and associated numeric parameters. The most common encoding scheme (as used in S \cdot G) includes:
M for “move to”, L for “line to”, C for “cubic Bézier”).The following path draws a simple triangle:
M 100 100 L 200 100 L 150 200 Z
Explanation:
M 100 100 – Move to point \$(100,100)\$.L 200 100 – Draw a line to \$(200,100)\$.L 150 200 – Draw a line to \$(150,200)\$.Z – Close the path (draw a line back to the start).A cubic Bézier curve is defined by four points: the start point \$P0\$, two control points \$P1\$ and \$P2\$, and the end point \$P3\$. The parametric equation is:
\$\$
B(t) = (1-t)^3 P0 + 3(1-t)^2 t P1 + 3(1-t) t^2 P2 + t^3 P3,\quad 0 \le t \le 1
\$\$
In an encoding, the command C is followed by the coordinates of \$P1\$, \$P2\$, and \$P_3\$.
| Command | Parameters | Purpose |
|---|---|---|
| M | \$x\; y\$ | Move the current point to \$(x, y)\$ without drawing. |
| L | \$x\; y\$ | Draw a straight line from the current point to \$(x, y)\$. |
| H | \$x\$ | Horizontal line to \$x\$ (y remains unchanged). |
| V | \$y\$ | Vertical line to \$y\$ (x remains unchanged). |
| C | \$x1\; y1\; x2\; y2\; x\; y\$ | Cubic Bézier curve using two control points \$(x1,y1)\$, \$(x2,y2)\$ and ending at \$(x,y)\$. |
| Q | \$x1\; y1\; x\; y\$ | Quadratic Bézier curve with one control point. |
| Z | — | Close the current sub‑path by drawing a line to the start point. |
Colours are usually stored as hexadecimal RGB values (e.g., #FF0000 for red) or as separate integer components ranging from 0–255. Stroke width is a numeric value representing the line thickness in user‑space units.