opencascade对坐标系进行旋转操作
输入:原始坐标系的引用,绕哪根轴旋转,旋转的角度
规定:x轴旋转标志为0,y轴旋转标值为1、z轴旋转为2
void coordinateRotation(Handle(Geom_Axis2Placement) &coordinate,Standard_Integer flag,Standard_Real degree)
{
double PI = 3.1415926;
Standard_Real deg = degree * PI / 180;//转角转换为弧度制
switch (flag)
{
case 0://绕X轴旋转
{
gp_Dir xDirection = coordinate->XDirection();
gp_Pnt location = coordinate->Ax2().Location();
gp_Ax1 retation_axiX(location, xDirection);
gp_Trsf rotation_trans;
rotation_trans.SetRotation(retation_axiX, deg);
coordinate->Transform(rotation_trans);
Handle(AIS_Trihedron) partTrihedron = new AIS_Trihedron(coordinate);
m_context->Display(partTrihedron, Standard_True);
m_view->FitAll();
return;
}
case 1://绕Y轴旋转
{
gp_Dir yDirection = coordinate->YDirection();
gp_Pnt location = coordinate->Ax2().Location();
gp_Ax1 retation_axiY(location, yDirection);
gp_Trsf rotation_trans;
rotation_trans.SetRotation(retation_axiY, deg);
coordinate->Transform(rotation_trans);
Handle(AIS_Trihedron) partTrihedron = new AIS_Trihedron(coordinate);
m_context->Display(partTrihedron, Standard_True);
m_view->FitAll();
return;
}
case 2://绕Z轴旋转
{
gp_Dir zDirection = coordinate->Direction();
gp_Pnt location = coordinate->Ax2().Location();
gp_Ax1 retation_axiZ(location, zDirection);
gp_Trsf rotation_trans;
rotation_trans.SetRotation(retation_axiZ, deg);
coordinate->Transform(rotation_trans);
Handle(AIS_Trihedron) partTrihedron = new AIS_Trihedron(coordinate);
m_context->Display(partTrihedron, Standard_True);
m_view->FitAll();
return;
}
default:
return;
}
}
调用函数:
coordinateRotation(TrihedronAxis, 2, 30);
coordinateRotation(TrihedronAxis, 1, 30);
coordinateRotation(TrihedronAxis, 0, 30);
绘制结果: