#include "StdAfx.h" #include "AecISOMatrix.h" AecISOMatrix::AecISOMatrix(void) { m_xform.setToIdentity(); m_dAngle = 0.0; } AecISOMatrix::~AecISOMatrix(void) { } static bool Is45or135sys(double dAngle) { if ( fabs( (fabs(dAngle) - PI / 4.0 ) ) < 1.e-3) return true; if ( fabs( (fabs(dAngle) - 0.75 * PI) ) < 1.e-3) return true; return false; } void AecISOMatrix::Set(AcGePoint3d ptOrg,double dAngle,int nType,BOOL b45NoIso) { m_dAngle = dAngle; AcGeVector3d vtX = AcGeVector3d::kXAxis; AcGeVector3d vtY = AcGeVector3d::kXAxis; //45度 不透视 Y 水平,国产土法系统图出法 if (b45NoIso && Is45or135sys(dAngle) ) { vtX.rotateBy(dAngle, AcGeVector3d::kZAxis); switch (nType) { case 0: //西南 45,x { vtY = -AcGeVector3d::kXAxis; break; } case 1://东南 45,x { vtY = AcGeVector3d::kXAxis; break; } case 2://东北 -135,-x { vtY = AcGeVector3d::kXAxis; break; } case 3://西北 130,-x { vtY = -AcGeVector3d::kXAxis; break; } default: break; } AcGeVector3d vtZ = AcGeVector3d::kYAxis; m_xform.setCoordSystem(ptOrg, vtX, vtY, vtZ); return; } else { if (Is45or135sys(dAngle))//旧 45度市政出图 X 垂直 Y 45-135类似 { if (fabs(dAngle - PI / 4.0) < 1.e-6) { } else { vtX.rotateBy(dAngle, AcGeVector3d::kZAxis); } AcGeVector3d vtY = AcGeVector3d::kXAxis; if (fabs(dAngle - PI / 4.0) < 1.e-6) { vtY.rotateBy(dAngle, AcGeVector3d::kZAxis); } else { switch (nType) { case 0: //西南 30,120 { vtY.rotateBy(PI - dAngle, AcGeVector3d::kZAxis); break; } case 1://东南 -30,30 { vtY.rotateBy(-dAngle, AcGeVector3d::kZAxis); break; } case 2://东北 -150,-30 { vtY.rotateBy(-PI - dAngle, AcGeVector3d::kZAxis); break; } case 3://西北 150,-150 { vtY.rotateBy(-dAngle, AcGeVector3d::kZAxis); break; } default: break; } } AcGeVector3d vtZ = AcGeVector3d::kYAxis; m_xform.setCoordSystem(ptOrg, vtX, vtY, vtZ); return; } } //国际标准 ISO 透视出法 vtX = AcGeVector3d::kXAxis; vtX.rotateBy(dAngle,AcGeVector3d::kZAxis); vtY = AcGeVector3d::kXAxis; switch (nType) { case 0: //西南 30,120 { vtY.rotateBy(PI - dAngle, AcGeVector3d::kZAxis); break; } case 1://东南 -30,30 { vtY.rotateBy(-dAngle, AcGeVector3d::kZAxis); break; } case 2://东北 -150,-30 { vtY.rotateBy(-PI - dAngle, AcGeVector3d::kZAxis); break; } case 3://西北 150,-150 { vtY.rotateBy(-dAngle, AcGeVector3d::kZAxis); break; } default: break; } AcGeVector3d vtZ = AcGeVector3d::kYAxis; m_xform.setCoordSystem(ptOrg,vtX,vtY,vtZ); } void AecISOMatrix::GetTransformByThis(AcGePoint3d& pt) { pt.transformBy(m_xform); } void AecISOMatrix::GetInvrtTransformByThis(AcGePoint3d &pt) { AcGeMatrix3d xf = m_xform; xf.invert(); pt.transformBy(xf); } void AecISOMatrix::GetTransformByThis(AcGeVector3d& vt) { vt.transformBy(m_xform); } void AecISOMatrix::GetTransformByThis(AcDbEntity *ptr) { // 不处理arc AcDbArc *pArc = AcDbArc::cast(ptr); if (!pArc) { ptr->transformBy(m_xform); } } double AecISOMatrix::GetISORotation(AcGeVector3d vt1) { double dAngle = 0.0; if (vt1.isParallelTo(AcGeVector3d::kXAxis)) { return dAngle; //0.0 } if (vt1.isParallelTo(AcGeVector3d::kYAxis)) { return PI / 2.0; //90 } if (vt1.x > 1.e-10 && vt1.y > 1.e-10) //I { dAngle = AcGeVector3d::kXAxis.angleTo(vt1,AcGeVector3d::kXAxis); return dAngle; } if (vt1.x < 1.e-10 && vt1.y > 1.e-10) //II { dAngle = AcGeVector3d::kXAxis.angleTo(vt1,AcGeVector3d::kXAxis); dAngle += PI; return dAngle; } if (vt1.x < 1.e-10 && vt1.y < 1.e-10) //III==I { vt1.negate(); dAngle = AcGeVector3d::kXAxis.angleTo(vt1,AcGeVector3d::kXAxis); return dAngle; } if (vt1.x > 1.e-10 && vt1.y < 1.e-10) //IV==II { vt1.negate(); dAngle = AcGeVector3d::kXAxis.angleTo(vt1,AcGeVector3d::kXAxis); dAngle += PI; return dAngle; } return dAngle; } double AecISOMatrix::GetISOOblique(AcGeVector3d vt1) { double dAngle = 0.0; if (vt1.isParallelTo(AcGeVector3d::kXAxis)) { return dAngle; //0.0 } if (vt1.isParallelTo(AcGeVector3d::kYAxis)) { return (2.0 * PI - m_dAngle); //330 } if (vt1.x > 1.e-10 && vt1.y > 1.e-10) //I { return m_dAngle; //30 } if (vt1.x < 1.e-10 && vt1.y > 1.e-10) //II { return (2.0 * PI - m_dAngle); //330 } if (vt1.x < 1.e-10 && vt1.y < 1.e-10) //III { return m_dAngle; //30 } if (vt1.x > 1.e-10 && vt1.y < 1.e-10) //IV { return (2.0 * PI - m_dAngle); //330 } return 0.0; }