#include "stdafx.h" #include "geell3d.h" #include "adscodes.h" #include "dbsol3d.h" #include "AecSupportFunc.h" #include "Aec3dFaceplan.h" Aec3dFaceplan::Aec3dFaceplan(void) { m_bValid = FALSE; } Aec3dFaceplan::~Aec3dFaceplan(void) { } void Aec3dFaceplan::AddFace(AcGePoint3d& pt1,AcGePoint3d& pt2,AcGePoint3d& pt3) { Face3Pt face; face.pt[0] = pt1; face.pt[1] = pt2; face.pt[2] = pt3; for (int i = 0;i < 3;i++) { if ( fabs(face.pt[i].z) < 1.e-3) face.pt[i].z = 0.0; } m_arFaces.append(face); m_eType = Aec3dFaceplan::kFaces; m_bValid = TRUE; } void Aec3dFaceplan::AddFace(AcGePoint3d* pt,Aec3dFaceplan::Faceplan ePlan) { m_eType = ePlan; switch(ePlan) { case Aec3dFaceplan::kRect: case Aec3dFaceplan::kTrape: { for (int i = 0;i < 4;i++) { m_ptGe[i] = pt[i]; if ( fabs(m_ptGe[i].z) < 1.e-3) m_ptGe[i].z = 0.0; } break; } case Aec3dFaceplan::kCircle: { m_ptGe[0] = pt[0]; m_ptGe[1].x = pt[1].x; break; } case Aec3dFaceplan::kElbow: { m_ptGe[0] = pt[0]; m_ptGe[1].x = pt[1].x; //rinside m_ptGe[1].y = pt[1].y; //routside m_ptGe[2].x = pt[2].x; //staang m_ptGe[2].y = pt[2].y; //endang for (int i = 0;i < 3;i++) { if ( fabs(m_ptGe[i].z) < 1.e-3) m_ptGe[i].z = 0.0; } break; } case Aec3dFaceplan::kFaces: { Face3Pt face; face.pt[0] = pt[0]; face.pt[1] = pt[1]; face.pt[2] = pt[2]; for (int i = 0;i < 3;i++) { if ( fabs(face.pt[i].z) < 1.e-3) face.pt[i].z = 0.0; } m_arFaces.append(face); m_eType = Aec3dFaceplan::kFaces; break; } default: break; } m_bValid = TRUE; } void Aec3dFaceplan::ExtractFaces(AcDbVoidPtrArray& arFaces) { AcGePoint3d ptGe[4]; switch(m_eType) { case Aec3dFaceplan::kRect: case Aec3dFaceplan::kTrape: { AcDbFace* pFace = new AcDbFace; for (int i = 0;i < 4;i++) { pFace->setVertexAt(i,m_ptGe[i]); } arFaces.append(pFace); break; } case Aec3dFaceplan::kCircle: { //m_ptGe[0] = pt[0]; //m_ptGe[1].x = pt[1].x; //近似 [] ptGe[0] = m_ptGe[0]; ptGe[0].x += m_ptGe[1].x;//r ptGe[0].y += m_ptGe[1].x;//r ptGe[1] = ptGe[0]; ptGe[1].x -= 2.0 * m_ptGe[1].x;//r ptGe[2] = ptGe[1]; ptGe[2].y -= 2.0 * m_ptGe[1].x;//r ptGe[3] = ptGe[0]; ptGe[3].y -= 2.0 * m_ptGe[1].x;//r AcDbFace* pFace = new AcDbFace; for (int i = 0;i < 4;i++) { pFace->setVertexAt(i,ptGe[i]); } arFaces.append(pFace); break; } case Aec3dFaceplan::kElbow: { //近似取梯形 /* m_ptGe[0] = pt[0]; m_ptGe[1].x = pt[1].x; //rinside m_ptGe[1].y = pt[1].y; //routside m_ptGe[2].x = pt[2].x; //staang m_ptGe[2].y = pt[2].y; //endang */ AcDbArc arc; arc.setCenter(m_ptGe[0]); arc.setRadius(m_ptGe[1].x); arc.setStartAngle(m_ptGe[2].x); arc.setEndAngle(m_ptGe[2].y); arc.setNormal(AcGeVector3d::kZAxis); arc.getStartPoint(ptGe[0]); arc.getEndPoint(ptGe[3]); arc.setRadius(m_ptGe[1].y); arc.getStartPoint(ptGe[1]); arc.getEndPoint(ptGe[2]); AcDbFace* pFace = new AcDbFace; for (int i = 0;i < 4;i++) { pFace->setVertexAt(i,m_ptGe[i]); } arFaces.append(pFace); break; } case Aec3dFaceplan::kFaces: { AcDbFace* pFace = NULL; for (int i = 0;i < m_arFaces.length();i++) { Face3Pt face = m_arFaces.at(i); pFace = new AcDbFace; pFace->setVertexAt(0,face.pt[0]); pFace->setVertexAt(1,face.pt[1]); pFace->setVertexAt(2,face.pt[2]); pFace->setVertexAt(3,face.pt[0]); arFaces.append(pFace); } break; } default: break; } } //判断点在三角形外 BOOL Aec3dFaceplan::PointOutsideTriangle(const AcGePoint3d& ptGe1,const AcGePoint3d& ptGe2, const AcGePoint3d& ptGe3,const AcGePoint3d& ptGeT) { AcGeLineSeg3d line1(ptGe1,ptGe2); AcGeLineSeg3d line2(ptGe1,ptGe3); AcGeLineSeg3d line3(ptGe3,ptGe2); AcGePoint3d ptInt( (ptGe1.x + ptGe2.x + ptGe3.x) / 3.0, (ptGe1.y + ptGe2.y + ptGe3.y) / 3.0, (ptGe1.z + ptGe2.z + ptGe3.z) / 3.0); AcGeLineSeg3d line13(ptGeT,ptInt); if (line13.intersectWith(line1,ptInt)) { //判断点交点是否是ptGeT if ( ptInt.distanceTo(ptGeT) < 1.e-3) //在上 { return FALSE; } return TRUE; } if (line13.intersectWith(line2,ptInt)) { //判断点交点是否是ptGeT if ( ptInt.distanceTo(ptGeT) < 1.e-3) //在上 { return FALSE; } return TRUE; } if (line13.intersectWith(line3,ptInt)) { //判断点交点是否是ptGeT if ( ptInt.distanceTo(ptGeT) < 1.e-3) //在上 { return FALSE; } return TRUE; } return FALSE; } //判断点在四边形内 BOOL Aec3dFaceplan::PointOutsideRect(const AcGePoint3d& ptGe1,const AcGePoint3d& ptGe2, const AcGePoint3d& ptGe3,const AcGePoint3d& ptGe4, const AcGePoint3d& ptGeT) { AcGeLineSeg3d line1(ptGe1,ptGe2); AcGeLineSeg3d line2(ptGe2,ptGe3); AcGeLineSeg3d line3(ptGe3,ptGe4); AcGeLineSeg3d line4(ptGe1,ptGe4); AcGePoint3d ptGeMid1 = TSupportFunc::Mid(ptGe1,ptGe3); AcGeLineSeg3d line11(ptGeT,ptGeMid1); AcGePoint3d ptInt; if (line11.intersectWith(line1,ptInt)) { //判断点交点是否是ptGeT if ( ptInt.distanceTo(ptGeT) < 1.e-3) //在上 { return FALSE; } return TRUE; } if (line11.intersectWith(line2,ptInt)) { //判断点交点是否是ptGeT if ( ptInt.distanceTo(ptGeT) < 1.e-3) //在上 { return FALSE; } return TRUE; } if (line11.intersectWith(line3,ptInt)) { //判断点交点是否是ptGeT if ( ptInt.distanceTo(ptGeT) < 1.e-3) //在上 { return FALSE; } return TRUE; } if (line11.intersectWith(line4,ptInt)) { //判断点交点是否是ptGeT if ( ptInt.distanceTo(ptGeT) < 1.e-3) //在上 { return FALSE; } return TRUE; } return FALSE; } BOOL Aec3dFaceplan::IsInside(const AcGePoint3d& ptGe) { switch(m_eType) { case Aec3dFaceplan::kRect: { return !PointOutsideRect(m_ptGe[0],m_ptGe[1],m_ptGe[2],m_ptGe[3],ptGe); } case Aec3dFaceplan::kCircle: { double dr = ptGe.distanceTo(m_ptGe[0]); if (dr - m_ptGe[1].x < 1.e-10) { return TRUE; } break; } case Aec3dFaceplan::kElbow: { double dr = ptGe.distanceTo(m_ptGe[0]); if (dr - m_ptGe[1].x > -1.e-10 && dr - m_ptGe[1].y < 1.e-10) //半径方向内 { AcDbArc arc; arc.setCenter(m_ptGe[0]); arc.setRadius(dr); arc.setStartAngle(m_ptGe[2].x); arc.setEndAngle(m_ptGe[2].x); arc.setNormal(AcGeVector3d::kZAxis); double dPara = 0.0; if (Acad::eOk == arc.getParamAtPoint(ptGe,dPara)) { return TRUE; } } break; } case Aec3dFaceplan::kTrape: //梯形 { return !PointOutsideRect(m_ptGe[0],m_ptGe[1],m_ptGe[2],m_ptGe[3],ptGe); } case Aec3dFaceplan::kFaces: { Face3Pt face; for (int i = 0;i < m_arFaces.length();i++) { face = m_arFaces.at(i); if ( !PointOutsideTriangle(face.pt[0],face.pt[1],face.pt[2],ptGe) ) //在内 { return TRUE; } } break; } default: break; } return FALSE; } double Aec3dFaceplan::Elevation() { if (m_eType == Aec3dFaceplan::kFaces) { if (m_arFaces.length() > 0) return m_arFaces.at(0).pt[0].z; } return m_ptGe[0].z; } void Aec3dFaceplan::Test2Db() { AcDbVoidPtrArray arFaces; ExtractFaces(arFaces); AcDbFace* pFace = NULL; for (int i = 0;i < arFaces.length();i++) { pFace = (AcDbFace*)arFaces.at(i); pFace->setColorIndex(6); } }