Direct computation:
for each (x0, y0) {
getPixel(x0, y0, color);
(x, y) = F(x0, y0);
setPixel(x, y, color);
}
Drawback: although transformations are continuous functions in the real plane, when applied to a discrete area of pixels, they may create gaps in the transformed area because of the scan conversion.
General method: apply the inverse transformation.
determine the boundary of the transformed area by a direct transformation;
for each (x, y) {
(x0, y0) = F-1(x, y);
getPixel(x0, y0, color);
setPixel(x, y, color);
}
By this method, we leave no pixel out of the transformed area.
Direct transformation |
(
|
y |
|
yo |
) + ( |
|
) |
Inverse transformation |
(
|
yo |
|
y |
) - ( |
|
) |
Rotation matrix:
|
|
sin a |
- sin a
cos a |
) |
Rotation as Change of Coordinates
The point P' has coordinates in the frame of reference defined by the rotated unit vectors that are identical to the original coordinates of P in the frame Oxy. The two unit vectors are defined as v1 (cos a, sin a) and v2 (-sin a, cos a). To calculate the coordinates of P' in the frame Oxy, we need to multiply its coordinates in the frame (v1, v2) by the inverse of the matrix composed of the two vectors. This results in the rotation matrix described above.
Direct transformation |
(
|
y |
|
Ra * ( |
|
) |
Inverse transformation |
(
|
yo |
|
R -a * ( |
y |
) |
(
|
yo |
|
sin (-a) |
- sin (-a)
cos (-a) |
) * ( |
|
) |
(
|
yo |
|
- sin a |
sin a
cos a |
) * ( |
|
) |
Direct transformation |
(
|
y |
|
a 0 0 b | ) * ( |
yo |
) |
Inverse transformation |
(
|
yo |
|
1/a 0 0 1/b | ) * ( |
y |
) |
Flip vertically (axis = Ox)
|
( |
yo |
|
1 0 0 -1 | ) * ( |
y |
) |
Flip horizontally (axis = Oy)
|
( |
yo |
|
-1 0 0 1 | ) * ( |
y |
) |
From the programmer's point of view: recursively defined drawings.
Mandelbrot set:
|
The Sierpinski triangle |
|
|
The Mandelbrot Set | The Julia Set |