Transformation & Rasterization

Transformation & RasterizationTransformationBasic 2D transformationsHomogeneous coordinates DefintionAffine transformationIn practiseFor 3DViewing transformationViewport transformationProject transformationPerspective transformationRasterizationResolutionBasic rasterizationAntialiasingTheoryAntialisaingFont rasterizationAntialiasing in font

 

Transformation

Basic 2D transformations

Homogeneous coordinates

A translation is different from linear transformation. Now it must be two matrix for combining them:

A matrix with both linear transformation and translation.

But we want one matrix to express them together. Now we introduce a new tool: homogeneous coordinates.

Defintion

To be simply, homogeneous coordinate works by adding an extra dimention to matrix, for describing higher dimention caused transformation, like projection. In other word, an n-dimention space will be described by n+1-dimention matrices.

We are discussing 2D transformation, so we express them in ternary form:

Accordingly, the transformation matrix will be 3D matrix as well:

Transform matrix in homogeneous coordinates:

The homogeneous transform grants us the characteristics below:

  1. "w" value will not be changed for vectors.
Translate vector :
  1. Vector + Vector = Vector
  1. Point - Point = Vector
  1. Point + Vector = Point
Affine transformation

Applied homogeneous matrix, we have a transformation named "Affine transformation".

Affine transformation:
With this utility, we can have expression the above three transformations in homogeneous style:

Of cource, the three transformations can be combined in one.

 

In practise

Affine transformation matrix for 2D transformation is useful. In UI interface for drawing element, we typically pass this matrix for apply trasformation.

In the 3D transformation matrix, the 3rd row will always be [0, 0, 1], it does not need to be told as parameter.

So the transformation matrix in 2D drawing functions will typically be like:

[A, B, C, D, Tx, Ty]

 

For 3D

Affine transformation in 3D is just similar with 2D. Just make the transformation matrix to be 4D.

Viewing transformation

Viewport transformation

Project transformation

Perspective transformation

TBD

Rasterization

Resolution

Basic rasterization

What is rasterization? It is kind of a sampling.

An simple example: just imagine some colorful ink float on water, which show as a painting. Now we have a screen window, sink it under the water and slowly take it out. Then we'll have a painted screen window, which is similar to rasterization.

Bresenham's line algorithm is the most basic rasterization algorithm for drawing lines (primitive, vector) as bitmaps.

Illustration of the result of Bresenham's line algorithm.

Antialiasing

Theory

Antialisaing

Font rasterization

Refer to Font rasterization on Wiki.

Fonts are now vectors, then they could be scaled from extreme small to very large. Rasterization for fonts are map a vector path to a pixel matrix.

rasterization

Raw rasterized font without antialiasing:

Sample

 

Antialiasing in font

 

Nowadays, the most popular font rasterization library which supports both Windows and macOS is FreeType