opencascade对坐标系进行旋转操作

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);

绘制结果:
在这里插入图片描述

  • 1
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值