The Computer Graphics Companion Online Edition

Damian Scattergood 1999-2001

Index
Home

Download HelpFile

2D MATRIX TRANSFORMATIONS

2D TRANSLATION

2D translation can be achieved by either Multiplying by the Matrix translation T or by direct addition of Offsets to original
point.

Translate a given 2D point (PointX, PointY) to a new position by the distance (Dx, Dy).

void Translate_2DPoint ( PointX, PointY, Dx, Dy )
// Depending on your implementation of the function
// the variables used maybe Integers or Floating point
// numbers
{
PointXnew = PointX + Dx;
PointYnew = PointY + Dy;
}

2D SCALING

To scale a point (PointX, PointY) about the origin by Scaling factors Sx, Sy.
Note: Scaling using this method always takes place about the origin at (0,0);

void Scale_2DPoint ( PointX, PointY, Sx, Sy )
{
PointXnew = PointX * Sx;
PointYnew = PointY * Sy;
}

2D Rotation

Rotates a point (PointX, PointY) about the origin by an angle of A degrees.
Note: Rotation takes place about the origin at (0,0);

void Rotate_2DPoint ( PointX, PointY, Angle )
{
PointXnew = PointX * Cos(Angle) - PointY * Sin(Angle);
PointYnew = PointY * Sin(Angle) + PointY * Cos(Angle);
}

2D Shearing

Two matrices to shear any given point (PointX, PointY) in either the X or Y direction
//SHx and SHy are the Shearing Values.

void ShearX2D ( PointX, PointY, SHx )
{
PointXnew = PointX + PointY * SHx;
PointYnew = PointY;
}

void ShearY2D ( PointX, PointY, SHy )
{
PointXnew = PointX;
PointYnew = PointY + PointX * SHy;
}
1