double CCommonFuntion::GetLineDistance(AcDbObjectId& Line1, AcDbObjectId& Line2)
{
AcGeLineSeg2d geLine1 = GetGeLineObj(Line1);
AcGeLineSeg2d geLine2 = GetGeLineObj(Line2);3d
//計算並輸出二者之間的最短距離
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);
}io