gp_Pnt描述了三維空間中的一個點。
gp_Pnt的定義:
class gp_Pnt
{
public:
...
private:
gp_XYZ coord;
};
預設情況下,位置為原點。
inline gp_Pnt::gp_Pnt() { }
兩點的重心。計算公式為:(Alpha*this + Beta*P) / (Alpha + Beta)
inline void gp_Pnt::BaryCenter(const Standard_Real A,const gp_Pnt& P,const Standard_Real B)
{
coord.SetLinearForm(A,coord,B,P.coord);
coord.Divide(A + B);
}
兩個點是否相等的判斷:兩點間距小于等于容差。
inline Standard_Boolean gp_Pnt::IsEqual(const gp_Pnt& Other,const Standard_Real LinearTolerance) const
{
return Distance (Other) <= LinearTolerance;
}
點關于點的對稱變換。
void gp_Pnt::Mirror (const gp_Pnt& P)
{
coord.Reverse ();
gp_XYZ XYZ = P.coord;
XYZ.Multiply (2.0);
coord.Add (XYZ);
}
點關于軸的對稱變換。
void gp_Pnt::Mirror (const gp_Ax1& A1)
{
gp_Trsf T;
T.SetMirror (A1);
T.Transforms (coord);
}
點關于面的對稱變換。
void gp_Pnt::Mirror (const gp_Ax2& A2)
{
gp_Trsf T;
T.SetMirror (A2);
T.Transforms (coord);
}
旋轉,A1是旋轉軸,Ang是旋轉角度。
inline void gp_Pnt::Rotate (const gp_Ax1& A1, const Standard_Real Ang)
{
gp_Trsf T;
T.SetRotation (A1, Ang);
T.Transforms (coord);
}
縮放
inline void gp_Pnt::Scale (const gp_Pnt& P, const Standard_Real S)
{
gp_XYZ XYZ = P.coord;
XYZ.Multiply (1.0 - S);
coord.Multiply (S);
coord.Add (XYZ);
}
變換
void gp_Pnt::Transform (const gp_Trsf& T)
{
if (T.Form() == gp_Identity)
{
}
else if (T.Form() == gp_Translation)
{
coord.Add (T.TranslationPart ());
}
else if (T.Form() == gp_Scale)
{
coord.Multiply (T.ScaleFactor ());
coord.Add (T.TranslationPart ());
}
else if(T.Form() == gp_PntMirror)
{
coord.Reverse ();
coord.Add (T.TranslationPart ());
}
else
{
T.Transforms(coord);
}
}
平移
inline void gp_Pnt::Translate (const gp_Vec& V)
{
coord.Add (V.XYZ());
}