DynaPDF Manual - Page 563

Function Reference
Page 563 of 787
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);
}
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);
}
// Scaling factor of the x-axis
double GetScaleX(TCTM &M)
{
double x1 = 0.0;
double y1 = 0.0;
double x2 = 1.0;

Previous topic: Working with Transformation Matrices

Next topic: Text Coordinates and Metrics