Fractals/Computer graphic techniques/2D/transformation

Plane transformations

Names

• transformations
• projections
• Cartographic Map projection[1] ( in case of 3D to 2D graphic)[2]
• mappings

Theory

Mapping in 2D raster graphic is a complex function ${\displaystyle f}$  that maps from complex plane to complex plane:

${\displaystyle f:\mathbb {C} \to \mathbb {C} }$

It is implemented as point transformations.

It is usually denoted as

${\displaystyle w=f(z)}$

where

• ${\displaystyle z=x+yi}$  is a point of complex plane ( input)
• ${\displaystyle w=u+vi}$  is a point of image complex plane ( output = result)

Example code

For instance, Mercator:[3]

function Spherical_mercator(x, y) {
return [x, Math.log(Math.tan(Math.PI / 4 + y / 2))];
}

function transverseMercatorRaw(lambda, phi) {
return [log(tan((halfPi + phi) / 2)), -lambda];
}

transverseMercatorRaw.invert = function(x, y) {
return [-y, 2 * atan(exp(x)) - halfPi];
};

If one work with discrete geometry ( polygons and polylines) then the projecting is much harder to imlement. One have to balance accuracy and performance.[4]

// projection from p to c
complex double map_parameter(const ParameterTypeT ParameterType, const complex double parameter){

complex double p;
// plane transformation
switch(ParameterType){

case c_identity :{p = parameter;  break;}

case c_inverted :{p = 1.0/parameter; break;}

case c_parabola :{p = 0.25+ 1.0/parameter; break;}

case c_Myrberg_type :{p = cf - 1.0/parameter; break;}

case c_inverted_2_type :{p = -2.0 + 1.0/parameter; break;}

case c_exp :{p = cf + cexp(parameter) ; break;} // here one can change cf to get different image

case lambda_identity :{ p = parameter;  break;}

case lambda_inverted_type :{p = 1.0/parameter; break;}

case lambda_inverted_1_type :{p =1.0+ 1.0/parameter; break;}

default: {p = parameter;}
}

classifications

Maps clasifications

• object-based mappings ( Image objects are sets of connected pixels having the same integer value )
• pixel based mappings

Transformations ( maps) in 2-D graphics

• basic types
• Composite Transformation [5]

Implementations

Use of matrices:

• without matrices ( using functions)
• with matrices

Coordinate

Matrix

• "Matrix multiplication is not commutative. The order of the transformations is vital– Rotation followed by translation isvery different from translation followed by rotation"[6]

Implementations

types

Affine transformations

To represent affine transformations with matrices, we can use homogeneous coordinates. This means representing a 2-vector (x, y) as a 3-vector (x, y, 1), and similarly for higher dimensions.

Transformation name Affine matrix Example
Identity (transform to original image) ${\displaystyle {\begin{bmatrix}1&0&0\\0&1&0\\0&0&1\end{bmatrix}}}$
Translation ${\displaystyle {\begin{bmatrix}1&0&v_{x}>0\\0&1&v_{y}=0\\0&0&1\end{bmatrix}}}$
Reflection ${\displaystyle {\begin{bmatrix}-1&0&0\\0&1&0\\0&0&1\end{bmatrix}}}$
Scale ${\displaystyle {\begin{bmatrix}c_{x}=2&0&0\\0&c_{y}=1&0\\0&0&1\end{bmatrix}}}$
Rotate ${\displaystyle {\begin{bmatrix}\cos(\theta )&-\sin(\theta )&0\\\sin(\theta )&\cos(\theta )&0\\0&0&1\end{bmatrix}}}$
where θ = π/6 =30°
Shear ${\displaystyle {\begin{bmatrix}1&c_{x}=0.5&0\\c_{y}=0&1&0\\0&0&1\end{bmatrix}}}$

The affine transforms are applicable to the registration process where two or more images are aligned (registered). An example of image registration is the generation of panoramic images that are the product of multiple images stitched together.

scale or resize

Scaling of object about origin by by a scale factor

${\displaystyle s=s_{x}+s_{y}*i}$
${\displaystyle x'=x*s_{x}}$
${\displaystyle y'=y*s_{y}}$

becomes:

${\displaystyle {\begin{bmatrix}x'\\y'\\1\end{bmatrix}}={\begin{bmatrix}s_{x}&0&0\\0&s_{y}&0\\0&0&1\end{bmatrix}}{\begin{bmatrix}x\\y\\1\end{bmatrix}}}$

Scaling

• Uniform (maintains the object’s proportions as it scales): sx = sy
• non-uniform: sx != sy

Resizing objects while maintaining a fixed centre point = Scaling object about their own center

• width' = width * sx
• height' = height * sy
• compute coordinate of corners from the center

translation

Complex transtlation is a map[7]

${\displaystyle z'\to z+t}$

where

• ${\displaystyle z=x+y*i}$
• ${\displaystyle z'=x'+y'*i}$
• ${\displaystyle t=t_{x}+t_{y}*i}$

Using this system, translation can be expressed with matrix multiplication. The functional form

${\displaystyle x'=x+t_{x}}$
${\displaystyle y'=y+t_{y}}$

becomes:

${\displaystyle {\begin{bmatrix}x'\\y'\\1\end{bmatrix}}={\begin{bmatrix}1&0&t_{x}\\0&1&t_{y}\\0&0&1\end{bmatrix}}{\begin{bmatrix}x\\y\\1\end{bmatrix}}.}$

rotation

For rotation by an angle θ counterclockwise (positive direction) about the origin the functional form is

${\displaystyle x'=x\cos \theta -y\sin \theta }$
${\displaystyle y'=x\sin \theta +y\cos \theta }$ .

Written in matrix form, this becomes:[8]

${\displaystyle {\begin{bmatrix}x'\\y'\\1\end{bmatrix}}={\begin{bmatrix}\cos \theta &-\sin \theta &0\\\sin \theta &\cos \theta &0\\0&0&1\end{bmatrix}}{\begin{bmatrix}x\\y\\1\end{bmatrix}}}$

Similarly, for a rotation clockwise (negative direction) about the origin, the functional form is

${\displaystyle x'=x\cos \theta +y\sin \theta }$
${\displaystyle y'=-x\sin \theta +y\cos \theta }$

the matrix form is:

${\displaystyle {\begin{bmatrix}x'\\y'\\1\end{bmatrix}}={\begin{bmatrix}\cos \theta &\sin \theta &0\\-\sin \theta &\cos \theta &0\\0&0&1\end{bmatrix}}{\begin{bmatrix}x\\y\\1\end{bmatrix}}}$

These formulae assume that the x axis points right and the y axis points up.

the counter-clockwise rotation matrix in normalised coordinate:

${\displaystyle {\begin{bmatrix}\cos \theta &-\sin \theta &0\\\sin \theta &\cos \theta &0\\0&0&1\end{bmatrix}}}$

C code without matrix

/*

C program to rotate an object by a given angle about a given point
gcc r.c -Wall -Wextra -lm
./a.out
*/

#include <stdio.h>
#include <math.h>
#include <complex.h> 		// complex numbers : https://stackoverflow.com/questions/6418807/how-to-work-with-complex-numbers-in-c

//The sin() function returns the value in the range of [-1, 1]

/*
First subtract the pivot point (cx,cy), then rotate it (counter clock-wise), then add the point again.
*/

complex double rotate_point(const complex double center, const double angle_in_radians, const complex double point )
{
// translate point to center
complex double translated_point = creal(point) - creal(center)  + (cimag(point) - cimag(center))*I;

// rotate point counter clock-wise by a given angle about a given pivot point ( center)
complex double new_point = creal(translated_point) * c - cimag(translated_point) * s + (creal(translated_point) * s + cimag(translated_point) * c)*I;

// translate point back
new_point = creal(new_point) + creal(center) +(cimag(new_point) + cimag(center))*I;

return new_point;
}

#define kMax 6

double examples[kMax][5] = {
{50,-50, -0.7853982, 100,100 },
{50,-50, -0.7853982, 100,200 },
{50,-50, -0.7853982, 200,200 },
{0,0, 1.570796, 100,100},
{0,0, 1.570796, 150,200},
{0,0, 1.570796, 200,200}

};

int main(void){

int k;

complex double center ;
double angle_r ;
complex double point ;
complex double rotated_point;

for (k=0; k<kMax; ++k){
center = examples[k][0] + examples[k][1] * I ;
angle_r = examples[k][2];
point = examples[k][3] + examples[k][4] * I ;
rotated_point = rotate_point(center, angle_r, point );
fprintf(stdout, "point %f%+f*I rotated about %f%+f*I  by %f radians is %f%+f*I \n", creal(point), cimag(point), creal(center), cimag(center), angle_r, creal(rotated_point), cimag(rotated_point));
}

return 0;
}

Output:

Examples:[9][10]

Conformal map

• "Conformal maps preserve angles and take infinitesimal circles to infinitesimal circles. Non-conformal maps take infinitesimal circles to infinitesimal ellipses (or worse)." Claude Heiland-Allen
• "A complex function ${\displaystyle f(z)}$  is conformal at infinity if the function ${\displaystyle f(1/z)}$  is conformal at 0. This equivalent to the usual definition of conformal in terms of leaving angles unchanged in size and sense (clockwise/anticlockwise) if you think of ${\displaystyle f}$  as being conformal at infinity if it leaves angles unchanged at the "North Pole" of the Riemann sphere."[22]

Conformal maps

Dictionary of Conformal Mapping by John H. Mathews, Russell W. Howell ( 2008)

Cartographic Map projection

cylindrical projection

Cylindrical projection ( or cylindric p. ) maps from sphere ( without poles) to cylinder [23][24]

Description :

domain coloring or complex phase plots

Visualisation of complex functions