Xojo Developer Conference
25/27th April 2018 in Denver.
MBS Xojo Conference
6/7th September 2018 in Munich, Germany.

DynaPDF Manual - Page 533

Previous Page 532   Index   Next Page 534

Function Reference
Page 533 of 750
The identity matrix is [1, 0, 0, 1, 0, 0] (a, b, c, d, x, y).
The following overview lists the most important matrix manipulations:
Translations are specified as [1, 0, 0, 1, tx, ty] where tx and ty represent the distances to
translate the origin of the coordinate system in horizontal and vertical dimensions,
respectively.
Scaling is achieved by [sx, 0, 0, sy, 0, 0]. This scales the coordinates so that 1 unit in the
horizontal and vertical dimensions of the new coordinate system is the same size as sx and sy
units, respectively, in the previous coordinate system.
Rotations are achieved by [cos α, sin α, -sin α, cos α, 0, 0], which has the effect of rotating the
coordinate system axes by an angle α (measured in radians) counter clockwise.
Skew is specified by [1, tan α, tan β, 1, 0, 0], which skews the x-axis by an angle α, and the y-
axis by an angle β (measured in radians).
All transformations above can occur in any combination in one transformation matrix.
Helper Functions
The following functions are helpful and some of them are required when working with
transformation matrices. To achieve maximum execution speed the source codes of the most
important functions are provided:
// Distance between two points
double CalcDistance(double x1, double y1, double x2, double y2)
{
double dx = x2-x1;
double dy = y2-y1;
return sqrt(dx*dx + dy*dy);
}
// Rotation angle in radians
double GetRotationAngle(TCTM &M)
{
double x1 = 0.0;
double y1 = 0.0;
double x2 = 1.0;
double y2 = 0.0;
Transform(M, x1, y1);
Transform(M, x2, y2);
return atan2(y2-y1, x2-x1);
}
// Overall scaling factor
double GetScaleFactor(TCTM &M)
{
#define sin45 0.70710678118654752440084436210485
double x = sin45 * M.a + sin45 * M.c;
double y = sin45 * M.b + sin45 * M.d;
return sqrt(x*x + y*y);
 

Previous topic: Working with Transformation Matrices

Next topic: Text Width