logo
Snip
  • Getting started
  • User Guide
  • Deployment
  • Development
    • Contributing
    • Authentication
    • Tools
    • Snips
    • Database
    • Coordinate systems
  • Home

Coordinate Systems and Transformation Functions

Every snippet placed on the page is positioned using a coordinate system, which includes position and rotation values. The page coordinate system determines where each snippet is rendered. In our system:

  • The top left corner has the coordinates (0,0)(0,0)(0,0)
  • The bottom right corner has the coordinates (1440,2000)(1440,2000)(1440,2000)

To convert these page coordinates to a device-specific view, we use a homogeneous coordinate transformation denoted as TTT. This allows us to perform translation, scaling, rotation, and other affine transformations consistently using matrix multiplication i.e. the user can zoom or translate the page with ease.

Let's consider a point on the page XP=(xP,yP,1)X_P=(x_P,y_P,1)XP​=(xP​,yP​,1), which is transformed to XS=(xS,yS,1)X_S=(x_S,y_S,1)XS​=(xS​,yS​,1) using the transformation matrix TTT

T=(actxbdty001)T = \begin{pmatrix} a & c & t_x \\ b & d & t_y \\ 0 & 0 & 1 \\ \end{pmatrix}T=​ab0​cd0​tx​ty​1​​
transform

Applying the Transformation

The transformed coordinates XSX_SXS​ are obtained by multiplying the transformation matrix TTT with the original coordinates XPX_PXP​:

(xSyS1)=(actxbdty001)(xPyP1)\begin{pmatrix} x_S \\ y_S \\ 1 \end{pmatrix} = \begin{pmatrix} a & c & t_x \\ b & d & t_y \\ 0 & 0 & 1 \end{pmatrix} \begin{pmatrix} x_P \\ y_P \\ 1 \end{pmatrix}​xS​yS​1​​=​ab0​cd0​tx​ty​1​​​xP​yP​1​​

Types of Transformations

  1. Translation:

    • Moves a point from one location to another.
    • Transformation matrix for translation by (tx,ty)(t_x, t_y)(tx​,ty​):
    Ttranslation=(10tx01ty001)T_{translation} = \begin{pmatrix} 1 & 0 & t_x \\ 0 & 1 & t_y \\ 0 & 0 & 1 \end{pmatrix}Ttranslation​=​100​010​tx​ty​1​​
  1. Scaling:
    • Changes the size of the object.
    • Transformation matrix for scaling by factors sxs_xsx​ and sys_ysy​:
Tscaling=(sx000sy0001) T_{scaling} = \begin{pmatrix} s_x & 0 & 0 \\ 0 & s_y & 0 \\ 0 & 0 & 1 \end{pmatrix}Tscaling​=​sx​00​0sy​0​001​​
  1. Rotation:
    • Rotates the object around the origin.
    • Transformation matrix for rotation by an angle θ\thetaθ:
Trotation=(cos⁡θ−sin⁡θ0sin⁡θcos⁡θ0001) T_{rotation} = \begin{pmatrix} \cos\theta & -\sin\theta & 0 \\ \sin\theta & \cos\theta & 0 \\ 0 & 0 & 1 \end{pmatrix}Trotation​=​cosθsinθ0​−sinθcosθ0​001​​
  1. Shearing:
    • Skews the object in one direction.
    • Transformation matrix for shearing along the x-axis by shxsh_xshx​ and along the y-axis by shysh_yshy​:
Tshearing=(1shx0shy10001) T_{shearing} = \begin{pmatrix} 1 & sh_x & 0 \\ sh_y & 1 & 0 \\ 0 & 0 & 1 \end{pmatrix}Tshearing​=​1shy​0​shx​10​001​​

Composite Transformations

Multiple transformations can be combined by multiplying their matrices. The order of multiplication is crucial as matrix multiplication is not commutative.

Tcomposite=Tn⋅Tn−1⋅…⋅T1T_{composite} = T_{n} \cdot T_{n-1} \cdot \ldots \cdot T_{1}Tcomposite​=Tn​⋅Tn−1​⋅…⋅T1​

By applying these transformations, we can accurately position and orient snippets on the page, ensuring that they appear correctly on different devices.

Build in functions

All of the transform logic is handled in the ViewPort class. The built-in functions, setZoom, fitPage, centerPage and translatePage, provide essential controls for rendering and viewing the page content dynamically. Additionally the viewport holds functions to convert positions from view to page coordinates and the other way around. They ensure that users can interact with the page intuitively, whether they need to zoom in for detailed scrutiny or fit the entire page within their viewport for an overview.

As a note the page coordinates are in theory also not fixed and changeable, this is not tested tho but could be used to create bigger pages.

Regarding zoom

Zoom levels are not fixed globally but rather a relative value based on the current viewport height vhv_hvh​ and the page height php_hph​. Any zoom zzz that is applied is multiplied by the ratio between the view and page to obtain the scaling factors aaa and ddd of the transform TTT.

a=d=vhph⋅za = d = \frac{v_h}{p_h} \cdot z a=d=ph​vh​​⋅z

Further to allow users to zoom using their current mouse position as origin point we translate to an origin point before and after applying the zoom scaling.

  • v1.12.3 © 2021 - 2025
  • Sebastian B. Mohr
  • Markus Osterhoff
  • Schemas
  • Docs
  • Privacy policy
  • Imprint