在Mstn SDK中,我们通过DPlane3d来表示一个无限大的平面,此类型的定义如下所示:
我们知道确定一个平面有很多种方式,例如通过平面上的一个点以及平面的法向量可以确定一个平面,或者通过三个不共线的点也可以确定一个平面。DPlane3d下也有类似的构造或者初始化函数可以创建DPlane3d的实例,如下所示:
我们如何判断一个坐标点是否在DPlane3d实例所代表的平面内呢?DPlane3d的成员函数中没有可以直接判断的方法,但是有一个名为“ProjectPoint”的成员函数可以将点投影到DPlane3d平面上,此函数原型如下所示:
//! //! @description Project a (generally off-plane) point onto the plane. //! @param [out] projection projection of point onto the plane //! @param [in] point point to project to plane //! @return true if the plane has a well defined normal. //! //! bool ProjectPoint ( DPoint3dR projection, DPoint3dCR point ) const;
我们可以把要判断的点投影到平面上,然后判断投影后的点跟要判断的点是否坐标值都一致,进而就知道这个点是否在平面内了。具体实现代码如下所示:
int JudegePointIsOnPlane(DPlane3dR plane, DPoint3d pt) { DPoint3d pro; if (!plane.ProjectPoint(pro, pt)) return -1; if (pro.IsEqual(pt)) return 1; return 0; }
此函数返回值为-1时表示DPlane3d数据有误,返回1表示pt在plane表示的平面内,返回0时pt不在plane表示的平面内。