XML technologies / SVG / The coordinate system of SVG graphics / What is the coordinate system? / Creating new coordinate systems

(Excerpt from “Das Einsteigerseminar SVG — Webgrafiken mit XML” by Helma Spona)

Besides SVG’s two coordinate systems, define your own with the transform attribute in a tag. It creates a new system whose origin lies within the parent system.

The transform attribute supports several values creating and initializing coordinate systems. Each transformation takes a list with different meanings, separated by spaces or commas.

The listing creates a coordinate system at 50/50 for the group defined by <g>. Positions within the group refer to it: the first rectangle begins at its origin, therefore at 50/50 in the graphic.

Defined coordinate systems

Figure: Defined coordinate systems.

<g id="aufz01" transform="translate(50,50)">
  <rect x="0" y="0" width="35" height="35" rx="0" ry="0" style="fill:rgb(255,64,64)"/>
  <rect x="36" y="22" width="42" height="42" rx="0" ry="0" style="fill:rgb(255,255,0)"/>
  <rect x="24" y="32" width="22" height="22" rx="0" ry="0" style="fill:rgb(64,64,255)"/>
</g>

The transform attribute accepts these values:

Note:
WebDraw converts an entered transform attribute into a matrix operation when switching to layout view or saving.
Examples of the transformations skewX, skewY and rotate appear under Filters, transformations and gradients.

Consider a group defined by the <g> tag whose elements need uniform reduction. Either reduce widths, heights and radii manually, or scale the whole group with a transformation.

Note:
Values below 1 reduce, above 1 enlarge. Decimals must use a dot: 0.2 = 0,2 = 20%.

The listing reduces the group to 20% of its original size.

<g id="aufz01" transform="scale(0.2)">
  <rect x="0" y="0" width="35" height="35" rx="0" ry="0" style="fill:rgb(255,64,64)"/>
  <rect x="36" y="22" width="42" height="42" rx="0" ry="0" style="fill:rgb(255,255,0)"/>
  <rect x="24" y="32" width="22" height="22" rx="0" ry="0" style="fill:rgb(64,64,255)"/>
</g>

Note:
This transform instruction initializes a coordinate system. Without a specified start, it begins at the graphic’s origin, moving the entire group there. Preserve the original position with a second transformation.

List simultaneous transformations sequentially in the transform attribute. The listing again scales with scale and positions the group with translate:

<g id="aufz01" transform="translate(50,50) scale(0.2)">
  <rect x="0" y="0" width="35" height="35" rx="0" ry="0" style="fill:rgb(255,64,64)"/>
  <rect x="36" y="22" width="42" height="42" rx="0" ry="0" style="fill:rgb(255,255,0)"/>
  <rect x="24" y="32" width="22" height="22" rx="0" ry="0" style="fill:rgb(64,64,255)"/>
</g>

Note:
Transformation order can affect the result.

   

 

 

 

back to top