OpenCasCade数学库 - 包围盒(Bnd_Box)的变换(Transformed)
程序员文章站
2024-03-16 18:11:34
...
1.包围盒(Bnd_Box)的定义
class Bnd_Box
{
public:
...
private:
Standard_Real Xmin;
Standard_Real Xmax;
Standard_Real Ymin;
Standard_Real Ymax;
Standard_Real Zmin;
Standard_Real Zmax;
Standard_Real Gap;
Standard_Integer Flags;
};
2.变换(gp_Trsf)的定义
class gp_Trsf
{
public:
...
private:
Standard_Real scale;
gp_TrsfForm shape; //几何变换类型
gp_Mat matrix;
gp_XYZ loc;
};
3.包围盒的变换(Transformed)
Bnd_Box Bnd_Box::Transformed (const gp_Trsf& T) const
{
gp_TrsfForm F = T.Form();
Bnd_Box newb(*this);
if ( IsVoid() ) return newb;
if (F == gp_Identity) {} //没有变化
else if (F == gp_Translation) { //平移
Standard_Real DX,DY,DZ;
(T.TranslationPart()).Coord(DX,DY,DZ);
if (!IsOpenXmin()) newb.Xmin += DX;
if (!IsOpenXmax()) newb.Xmax += DX;
if (!IsOpenYmin()) newb.Ymin += DY;
if (!IsOpenYmax()) newb.Ymax += DY;
if (!IsOpenZmin()) newb.Zmin += DZ;
if (!IsOpenZmax()) newb.Zmax += DZ;
}
else {
gp_Pnt P[8];
Standard_Boolean Vertex[8];
Standard_Integer i;
for (i=0;i<8;i++) Vertex[i] = Standard_True;
gp_Dir D[6];
// Standard_Integer vertices = 0;
Standard_Integer directions = 0;
if (IsOpenXmin())
{
directions++;
D[directions-1].SetCoord(-1., 0., 0.);
Vertex[0] = Vertex[2] = Vertex[4] = Vertex[6] = Standard_False;
}
if (IsOpenXmax())
{
directions++;
D[directions-1].SetCoord( 1., 0., 0.);
Vertex[1] = Vertex[3] = Vertex[5] = Vertex[7] = Standard_False;
}
if (IsOpenYmin())
{
directions++;
D[directions-1].SetCoord( 0.,-1., 0.);
Vertex[0] = Vertex[1] = Vertex[4] = Vertex[5] = Standard_False;
}
if (IsOpenYmax())
{
directions++;
D[directions-1].SetCoord( 0., 1., 0.);
Vertex[2] = Vertex[3] = Vertex[6] = Vertex[7] = Standard_False;
}
if (IsOpenZmin())
{
directions++;
D[directions-1].SetCoord( 0., 0.,-1.);
Vertex[0] = Vertex[1] = Vertex[2] = Vertex[3] = Standard_False;
}
if (IsOpenZmax())
{
directions++;
D[directions-1].SetCoord( 0., 0., 1.);
Vertex[4] = Vertex[5] = Vertex[6] = Vertex[7] = Standard_False;
}
newb.SetVoid();
for (i=0;i<directions;i++) { //只对开放区间的方向做转换
D[i].Transform(T);
newb.Add(D[i]);
}
P[0].SetCoord(Xmin,Ymin,Zmin);
P[1].SetCoord(Xmax,Ymin,Zmin);
P[2].SetCoord(Xmin,Ymax,Zmin);
P[3].SetCoord(Xmax,Ymax,Zmin);
P[4].SetCoord(Xmin,Ymin,Zmax);
P[5].SetCoord(Xmax,Ymin,Zmax);
P[6].SetCoord(Xmin,Ymax,Zmax);
P[7].SetCoord(Xmax,Ymax,Zmax);
for (i=0;i<8;i++) {
if (Vertex[i]) { //只对封闭区间的点做转换
P[i].Transform(T);
newb.Add(P[i]);
}
}
newb.Gap=Gap;
}
return newb;
}
上一篇: python凯撒密码加密