gp_Ax1描述了三維空間中的一個軸。
1.gp_Ax1的作用
- 描述三維幾何體(如:旋轉體的軸)
- 描述幾何變換(如:對稱軸、旋轉軸)
2.gp_Ax1的定義
- 位置
- 方向
class gp_Ax1
{
public:
...
private:
gp_Pnt loc;
gp_Dir vdir;
};
預設情況下,位置為原點,方向為Z軸正向。
inline gp_Ax1::gp_Ax1() : loc(0.,0.,0.), vdir(0.,0.,1.){ }
3.相等
兩個軸是否相同的判斷:位置相同,方向相同(夾角為0度)。
Standard_Boolean gp_Ax1::IsCoaxial(const gp_Ax1& Other, const Standard_Real AngularTolerance,const Standard_Real LinearTolerance) const
{
gp_XYZ XYZ1 = loc.XYZ();
XYZ1.Subtract (Other.loc.XYZ());
XYZ1.Cross (Other.vdir.XYZ());
Standard_Real D1 = XYZ1.Modulus();
gp_XYZ XYZ2 = Other.loc.XYZ();
XYZ2.Subtract (loc.XYZ());
XYZ2.Cross (vdir.XYZ());
Standard_Real D2 = XYZ2.Modulus();
return (vdir.IsEqual (Other.vdir, AngularTolerance) && D1 <= LinearTolerance && D2 <= LinearTolerance);
}
4.垂直
兩個軸是否垂直的判斷:軸的方向垂直(夾角為90度)。
inline Standard_Boolean gp_Ax1::IsNormal(const gp_Ax1& Other,const Standard_Real AngularTolerance) const
{
return vdir.IsNormal(Other.vdir, AngularTolerance);
}
inline Standard_Boolean gp_Dir::IsNormal(const gp_Dir& Other,const Standard_Real AngularTolerance) const
{
Standard_Real Ang = M_PI / 2.0 - Angle (Other);
if (Ang < 0) Ang = - Ang;
return Ang <= AngularTolerance;
}
5.平行
兩個軸是否平行的判斷:軸的夾角為0度或180度。
inline Standard_Boolean gp_Ax1::IsParallel(const gp_Ax1& Other,const Standard_Real AngularTolerance) const
{
return vdir.IsParallel(Other.vdir, AngularTolerance);
}
inline Standard_Boolean gp_Dir::IsParallel(const gp_Dir& Other, const Standard_Real AngularTolerance) const
{
Standard_Real Ang = Angle (Other);
return Ang <= AngularTolerance || M_PI - Ang <= AngularTolerance;
}
6.相反
兩個軸是否相反的判斷:軸的夾角為180度。
inline Standard_Boolean gp_Ax1::IsOpposite(const gp_Ax1& Other, const Standard_Real AngularTolerance) const
{
return vdir.IsOpposite(Other.vdir, AngularTolerance);
}
inline Standard_Boolean gp_Dir::IsOpposite(const gp_Dir& Other,const Standard_Real AngularTolerance) const
{
return M_PI - Angle (Other) <= AngularTolerance;
}