2D缩放的数学形式:
![](https://www.cnblogs.com/images/cnblogs_com/hellocg/Math&Phyics_image/Figure6-10.GIF)
Sx代表x方向的缩放量,Sy代表y方向的缩放量。当Sx=Sy代表等比例缩放。
例如:将下图的矩形ABCD放大3倍。
![](https://www.cnblogs.com/images/cnblogs_com/hellocg/Math&Phyics_image/Figure6-11.GIF)
设A(10,10),那么缩放后的A',将通过下列计算获得A'(30,30)。
![](https://www.cnblogs.com/images/cnblogs_com/hellocg/Math&Phyics_image/Figure6-12.GIF)
同理可以计算出缩放后的B'(150,30), C'(150,120),和 D'(30,120)。如图:
![](https://www.cnblogs.com/images/cnblogs_com/hellocg/Math&Phyics_image/Figure6-13.GIF)
虚线框表示的为缩放前的图形,实线框表示为缩放后的图形。
2D缩放在计算机中的实现:
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
2D缩放
Matrix3X1 scale2DByMultiplication(Matrix3X1 start, float dx, float dy)
{
Matrix3X3 temp;
Matrix3X1 result;
//Zero out the matrix.
temp = createFixed3X3Matrix(0);
//setup the 3x3 for multiplication;
temp.index[0][0] = dx;
temp.index[1][1] = dy;
temp.index[2][2] = 1;
result = multiplyMatrixNxM(temp,start);
return result;
}
3D缩放的数学形式:
![](https://www.cnblogs.com/images/cnblogs_com/hellocg/Math&Phyics_image/Figure6-14.GIF)
3D缩放在计算机中的实现:
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
3D缩放
Matrix4X1 scale3DByMultiply(Matrix4X1 start, float dx, float dy, float dz)
{
Matrix4X4 temp;
Matrix4X1 result;
//Zero out the matrix to make sure nothing is left uninitialized.
temp = createFixed4X4Matrix(0);
//setup the 3x3 for multiplication;
temp.index[0][0] = dx;
temp.index[1][1] = dy;
temp.index[2][2] = dz;
temp.index[3][3] = 1;
result = multiplyMatrixNxM(temp,start);
return result;
}