|
楼主 |
发表于 2024-2-27 16:58:13
|
显示全部楼层
- // Summary: 得到两条直线的角平分线向量
- bool PhdGeometry::GetMidVectorOfLines(const AcDbObjectId& idLine1, const AcDbObjectId& idLine2, AcGeVector2d& midVector)
- {
- AcDbObjectPointer<AcDbLine> pLine1(idLine1,AcDb::kForRead);
- if (Acad::eOk != pLine1.openStatus())
- return false;
- AcDbObjectPointer<AcDbLine> pLine2(idLine2, AcDb::kForRead);
- if (Acad::eOk != pLine2.openStatus())
- return false;
- AcGePoint3d ptInter;
- PhdGeometry::GetIntersectPoint(pLine1, pLine2, ptInter);
- AcGePoint3d ptEnd1, ptEnd2;
- if (!ptInter.isEqualTo(pLine1->startPoint()))
- {
- ptEnd1 = pLine1->startPoint();
- }
- else
- {
- ptEnd1 = pLine1->endPoint();
- }
- if (!ptInter.isEqualTo(pLine2->startPoint()))
- {
- ptEnd2 = pLine2->startPoint();
- }
- else
- {
- ptEnd2 = pLine2->endPoint();
- }
- AcGeVector2d vec1 = ptEnd1.convert2d(AcGePlane::kXYPlane) - ptInter.convert2d(AcGePlane::kXYPlane);
- AcGeVector2d vec2 = ptEnd2.convert2d(AcGePlane::kXYPlane) - ptInter.convert2d(AcGePlane::kXYPlane);
- midVector = vec1.normal() + vec2.normal();
- return true;
- }
- // Summary: 得到两条直线的夹角
- bool PhdGeometry::GetAngleOfLines(const AcDbObjectId& idLine1, const AcDbObjectId& idLine2, double& dAngle)
- {
- AcDbObjectPointer<AcDbLine> pLine1(idLine1,AcDb::kForRead);
- if (Acad::eOk != pLine1.openStatus())
- return false;
- AcDbObjectPointer<AcDbLine> pLine2(idLine2, AcDb::kForRead);
- if (Acad::eOk != pLine2.openStatus())
- return false;
- AcGePoint3d ptInter;
- PhdGeometry::GetIntersectPoint(pLine1, pLine2, ptInter);
- AcGePoint3d ptEnd1, ptEnd2;
- if (!ptInter.isEqualTo(pLine1->startPoint()))
- {
- ptEnd1 = pLine1->startPoint();
- }
- else
- {
- ptEnd1 = pLine1->endPoint();
- }
- if (!ptInter.isEqualTo(pLine2->startPoint()))
- {
- ptEnd2 = pLine2->startPoint();
- }
- else
- {
- ptEnd2 = pLine2->endPoint();
- }
- AcGeVector2d vec1 = ptEnd1.convert2d(AcGePlane::kXYPlane) - ptInter.convert2d(AcGePlane::kXYPlane);
- AcGeVector2d vec2 = ptEnd2.convert2d(AcGePlane::kXYPlane) - ptInter.convert2d(AcGePlane::kXYPlane);
- dAngle = vec1.angleTo(vec2);
- return true;
- }
- // Summary: 得到交点坐标
- bool PhdGeometry::GetIntersectPoint(const AcDbObjectId& idLine1, const AcDbObjectId& idLine2, AcGePoint3d& ptIntersect)
- {
- AcDbObjectPointer<AcDbLine> pLine1(idLine1,AcDb::kForRead);
- if (Acad::eOk != pLine1.openStatus())
- return false;
- AcDbObjectPointer<AcDbLine> pLine2(idLine2, AcDb::kForRead);
- if (Acad::eOk != pLine2.openStatus())
- return false;
- AcGeLine2d geLine1(pLine1->startPoint().convert2d(AcGePlane::kXYPlane), pLine1->endPoint().convert2d(AcGePlane::kXYPlane));
- AcGeLine2d geLine2(pLine2->startPoint().convert2d(AcGePlane::kXYPlane), pLine2->endPoint().convert2d(AcGePlane::kXYPlane));
- AcGePoint2d pt2d;
- bool bRet = geLine1.intersectWith(geLine2, pt2d);
- if (!bRet)
- return false;
- ptIntersect = AcGePoint3d(pt2d.x, pt2d.y, 0);
- return true;
- }
- // Summary: 极坐标求点
- AcGePoint3d PhdGeometry::PolarPoint(const AcGePoint3d& pt, double angle, double distance)
- {
- ads采用point ptForm, ptTo;
- ptForm[X] = pt.x;
- ptForm[Y] = pt.y;
- ptForm[Z] = pt.z;
- acutPolar(ptForm, angle, distance, ptTo);
- return asPnt3d(ptTo);
- }
- // Summary: 得到直线上距离该点最近的点
- AcGePoint3d PhdGeometry::GetClossedPoint(const AcDbObjectId& idCurve, const AcGePoint3d& pt)
- {
- AcDbObjectPointer<AcDbCurve> pCurve(idCurve,AcDb::kForRead);
- if (Acad::eOk != pCurve.openStatus())
- return AcGePoint3d::kOrigin;
- AcGePoint3d ptOnCurve;
- pCurve->getClosestPointTo(pt, ptOnCurve);
- return ptOnCurve;
- }
- // Summary: 圆心和起始点和终止点绘制圆弧(不知道谁是起始点和终止点)
- bool PhdEntity::CreateArc3(const AcGePoint3d& ptCenter, const AcGePoint3d& pt1, const AcGePoint3d& pt2, AcDbArc*& pArc)
- {
- // 计算半径;
- double radius = ptCenter.distanceTo(pt1);
- // 计算起始和终止角度;
- AcGeVector2d vecStart(pt1.x - ptCenter.x, pt1.y - ptCenter.y);
- AcGeVector2d vecEnd(pt2.x - ptCenter.x, pt2.y - ptCenter.y);
- double startAngle = vecStart.angle();
- double endAngle = vecEnd.angle();
- double dBulge = PhdGeometry::GetArcBulge(startAngle, endAngle);
- if (0 > dBulge)
- {
- vecStart = AcGeVector2d(pt2.x - ptCenter.x, pt2.y - ptCenter.y);
- vecEnd = AcGeVector2d(pt1.x - ptCenter.x, pt1.y - ptCenter.y);
- startAngle = vecStart.angle();
- endAngle = vecEnd.angle();
- dBulge = PhdGeometry::GetArcBulge(startAngle, endAngle);
- if (0 > dBulge)
- return false;
- }
- pArc = new AcDbArc(ptCenter, radius, startAngle, endAngle);
- return true;
- }
复制代码 |
|