gp_Trsf2d描述了三维空间中的图形变换。
V1 V2 T XY XY
{V1, V2}定义了图形变换中的向量变换,T定义了图形变换中的平移变换。
gp_Trsf2d的定义:
class gp_Trsf
{
public:
...
private:
Standard_Real scale;
gp_TrsfForm shape; //图形变换类型
gp_Mat2d matrix;
gp_XY loc;
};
默认构造函数。
inline gp_Trsf2d::gp_Trsf2d () {
shape = gp_Identity;
scale = 1.0;
matrix.SetIdentity ();
loc.SetCoord (0.0, 0.0);
}
关于点对称
inline void gp_Trsf2d::SetMirror(const gp_Pnt2d& P)
{
shape = gp_PntMirror;
scale = -1.0;
matrix.SetIdentity ();
loc = P.XY();
loc.Multiply (2.0);
}
关于轴对称
void gp_Trsf2d::SetMirror (const gp_Ax2d& A)
{
shape = gp_Ax1Mirror;
scale = - 1.0;
const gp_Dir2d& V = A.Direction ();
const gp_Pnt2d& P = A.Location ();
Standard_Real VX = V.X();
Standard_Real VY = V.Y();
Standard_Real X0 = P.X();
Standard_Real Y0 = P.Y();
matrix.SetCol (1, gp_XY (1.0 - 2.0 * VX * VX, -2.0 * VX * VY));
matrix.SetCol (2, gp_XY (-2.0 * VX * VY, 1.0 - 2.0 * VY * VY));
loc.SetCoord (-2.0 * ((VX * VX - 1.0) * X0 + (VX * VY * Y0)),
-2.0 * ((VX * VY * X0) + (VY * VY - 1.0) * Y0));
}
旋转,P是旋转中心,Ang是旋转角度。
inline void gp_Trsf2d::SetRotation (const gp_Pnt2d& P,const Standard_Real Ang)
{
shape = gp_Rotation;
scale = 1.0;
loc = P.XY ();
loc.Reverse ();
matrix.SetRotation (Ang);
loc.Multiply (matrix);
loc.Add (P.XY());
}
缩放,P是缩放中心,S是缩放比例。
inline void gp_Trsf2d::SetScale (const gp_Pnt2d& P, const Standard_Real S)
{
shape = gp_Scale;
scale = S;
matrix.SetIdentity ();
loc = P.XY ();
loc.Multiply (1.0 - S);
}