天天看点

OpenCasCade数学库 - 轴(gp_Ax1)

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

继续阅读