OpenCasCade(十) 拓扑变换
1.1.1 拓扑变换描述
1.1.2 BRepBuilderAPI_Transform
(1) 功能说明:拓扑变换
此对象与gp_Trsf相关联进行变换
(2) 构造函数:
public OCBRepBuilderAPI_Transform(OCgp_Trsf T);
public OCBRepBuilderAPI_Transform(OCTopoDS_Shape S, OCgp_Trsf T, bool Copy);
(3) 参数说明:
T:要进行的变换
S:进行变换的拓扑图形
Copy:是否用副本进行变换
(4) 备注:
Perform是该对象的一个方法。
OCBRepBuilderAPI_Transform(OCgp_Trsf T) 与public void Perform(OCTopoDS_Shape S, bool Copy)相等于OCBRepBuilderAPI_Transform(OCTopoDS_Shape S, OCgp_Trsf T, bool Copy)。
(5) 实例:
例1:点对称
OCTopoDS_Shape S;
OCgp_Trsf theTransformation = new OCgp_Trsf();
OCgp_Pnt PntCenterOfTheTransformation = new OCgp_Pnt(110, 60, 60);
theTransformation.SetMirror(PntCenterOfTheTransformation);//镜像
OCBRepBuilderAPI_Transform myBRepTransformation =
new OCBRepBuilderAPI_Transform(S, theTransformation, false);
OCTopoDS_Shape S2 = myBRepTransformation.Shape();
例2:轴对称
OCTopoDS_Shape S ;
OCgp_Trsf theTransformation = new OCgp_Trsf();
OCgp_Ax1 axe = new OCgp_Ax1(new OCgp_Pnt(110, 60, 60), new OCgp_Dir(0.0, 1.0, 0.0));
theTransformation.SetMirror(axe);//镜像
OCBRepBuilderAPI_Transform myBRepTransformation =
new OCBRepBuilderAPI_Transform(S, theTransformation, false);
OCTopoDS_Shape S2 = myBRepTransformation.Shape();
例3:面对称
OCTopoDS_Shape S = new OCBRepPrimAPI_MakeWedge(60.0, 100.0, 80.0, 20.0).Shape();
OCgp_Trsf theTransformation = new OCgp_Trsf();
OCgp_Ax2 axe2 = new OCgp_Ax2(new OCgp_Pnt(0, 0, 0), new OCgp_Dir(1, 0, 0));
theTransformation.SetMirror(axe2);//镜像
OCBRepBuilderAPI_Transform myBRepTransformation =
new OCBRepBuilderAPI_Transform(S, theTransformation, false);
OCTopoDS_Shape S2 = myBRepTransformation.Shape();
例4:旋转变换
OCTopoDS_Shape S;
OCgp_Trsf theTransformation = new OCgp_Trsf();
OCgp_Ax1 axe = new OCgp_Ax1(new OCgp_Pnt(200, 60, 60), new OCgp_Dir(0.0, 1.0, 0.0));
theTransformation.SetRotation(axe, 30 * System.Math.PI / 180);
OCBRepBuilderAPI_Transform myBRepTransformation =
new OCBRepBuilderAPI_Transform(S, theTransformation, false);
OCTopoDS_Shape S2 = myBRepTransformation.Shape();
例5:缩放变换
OCTopoDS_Shape S;
OCgp_Trsf theTransformation = new OCgp_Trsf();
OCgp_Pnt theCenterOfScale = new OCgp_Pnt(100, 60, 60);
theTransformation.SetScale(theCenterOfScale, 0.3);
OCBRepBuilderAPI_Transform myBRepTransformation =
new OCBRepBuilderAPI_Transform(S, theTransformation, false);
OCTopoDS_Shape S2 = myBRepTransformation.Shape();
例6:平移变换
OCTopoDS_Shape S;
OCgp_Trsf theTransformation = new OCgp_Trsf();
OCgp_Vec theVectorOfTranslation = new OCgp_Vec(-6, -6, 6);
theTransformation.SetTranslation(theVectorOfTranslation);
OCBRepBuilderAPI_Transform myBRepTransformation =
new OCBRepBuilderAPI_Transform(S, theTransformation, false);
OCTopoDS_Shape S2 = myBRepTransformation.Shape();
例7:移位(Displacement)变换
OCTopoDS_Shape S;
OCgp_Trsf theTransformation = new OCgp_Trsf();
OCgp_Ax3 ax3_1 = new OCgp_Ax3(new OCgp_Pnt(0, 0, 0), new OCgp_Dir(0, 0, 1));
OCgp_Ax3 ax3_2 = new OCgp_Ax3(new OCgp_Pnt(60, 60, 60), new OCgp_Dir(1, 1, 1));
theTransformation.SetDisplacement(ax3_1, ax3_2);
OCBRepBuilderAPI_Transform myBRepTransformation =
new OCBRepBuilderAPI_Transform(S, theTransformation, false);
OCTopoDS_Shape TransformedShape = myBRepTransformation.Shape();
1.1.3 BRepBuilderAPI_GTransform
(1) 功能说明:拓扑变换
此对象与gp_GTrsf相关联进行变换
(2) 构造函数:
public OCBRepBuilderAPI_GTransform(OCgp_GTrsf T);
public OCBRepBuilderAPI_GTransform(OCTopoDS_Shape S, OCgp_GTrsf T, bool Copy);
(3) 参数说明:
T:要进行的变换
S:进行变换的拓扑图形
Copy:是否用副本进行变换
(4) 实例:
例1:变形(deform)变换
OCTopoDS_Shape S;
OCgp_GTrsf theTransformation = new OCgp_GTrsf();
OCgp_Mat rot = new OCgp_Mat(1, 0, 0, 0, 0.5, 0, 0, 0, 1.5);
theTransformation.SetVectorialPart(rot);
// SetVectorialPart-----Replaces the vectorial part of this transformation by Matrix
theTransformation.SetTranslationPart(new OCgp_XYZ(5, 5, 5));
//SetTranslationPart-----
//Replaces the translation part of this transformation by the coordinates
OCBRepBuilderAPI_GTransform myBRepTransformation =
new OCBRepBuilderAPI_GTransform(S, theTransformation, false);
OCTopoDS_Shape S2 = myBRepTransformation.Shape();