|
double CCommonFuntion::GetLineDistance(AcDbObjectId& Line1, AcDbObjectId& Line2)
{
AcGeLineSeg2d geLine1 = GetGeLineObj(Line1);
AcGeLineSeg2d geLine2 = GetGeLineObj(Line2);
//计算并输出两者之间的最短距离
double distance = geLine1.distanceTo(geLine2);
return distance;
}
//根据输入的实体ID获得相同参数的AcGeLineSeg2d对象
AcGeLineSeg2d CCommonFuntion::GetGeLineObj(AcDbObjectId lineId)
{
AcGeLineSeg2d geLine; //AcGeLineSeg2d:在二维空间中表示一个有界的线段。
AcDbLine *pLine = NULL;
if (acdbOpenObject(pLine, lineId, AcDb::kForRead) == Acad::eOk)
//指针pLine指向打开的对象lineId
{
geLine.set(ToPoint2d(pLine->startPoint()),
ToPoint2d(pLine->endPoint()));
pLine->close();
}
return geLine;
}
// 二维点和三维点之间的转换
AcGePoint2d CCommonFuntion::ToPoint2d(const AcGePoint3d &point3d)
{
return AcGePoint2d(point3d.x, point3d.y);
} |
|