//-----------------------------------------------------------------------------+ // Copyright (C), 1998-2007, SH Software Co. Ltd. // = FileName : XPoint 点类 // = Version : ver2.0 // = Author : zjq // = CreateDate : 2002-09-09 // = Description: XPoint 类定义 // = Maintainers: // //-----------------------------------------------------------------------------+ #include "StdAfx.h" #include "XPoint.h" #include "XCircle.h" #include "XPlane.h" #include "XLine.h" #include "Entity.h" #include "XPoly.h" #include "XGlobalFunc.h" #include "XPrivateGlobalFunc.h" #include "geassign.h" using namespace XExport; using namespace XPrivate; XPoint::~XPoint() { } bool XPoint::operator > (const XPoint &pt) const { double dDis = x - pt.x; if (dDis >XGeLib::_DIST_SNAP) { return true; } else if (dDis < -XGeLib::_DIST_SNAP) { return false; } else { dDis = y - pt.y; if (dDis > XGeLib::_DIST_SNAP) { return true; } else if (dDis < -XGeLib::_DIST_SNAP) { return false; } else { return z-pt.z > XGeLib::_DIST_SNAP; } } } int XPoint::Project(const XLine* pLine, ads_point rp) const { //zjq 2009-08-31 投影方法 发现AcGe 没有原方案快 ASSERT(pLine != NULL); return AT_pt_ProjectLine(*this, pLine->StartPoint(), pLine->EndPoint(), rp); } int XPoint::Project(const AcGeLine3d* pLine,ads_point rp) const { ASSERT(pLine != NULL); return AT_pt_ProjectLine(*this, asDblArray(pLine->pointOnLine()), asDblArray(pLine->pointOnLine()), rp); return RTNORM; } double XPoint::Distance(const XLine* pLine) const { //zjq 2009-9-20 ASSERT(pLine != NULL); ads_real* pt0 = *this; ads_real* pt1 = pLine->m_startPoint; ads_real* pt2 = pLine->m_endPoint; ads_point pt4; struct plan_para plan; XVector3D vt; vt[0] = pt2[0] - pt1[0]; vt[1] = pt2[1] - pt1[1]; vt[2] = pt2[2] - pt1[2]; pt4[0]=pt0[0]; pt4[1]=pt0[1]; pt4[2]=pt0[2]; plan.A = vt[0]; plan.B = vt[1]; plan.C = vt[2]; plan.D = 0.0 - (vt[0] * pt0[0] + vt[1] * pt0[1] + vt[2] * pt0[2]); double l, m, n, t; double mid_var1, mid_var2; l = pt2[0] - pt1[0]; m = pt2[1] - pt1[1]; n = pt2[2] - pt1[2]; mid_var1 = l * (plan.A) + m * (plan.B) + n * (plan.C); if (fabs(mid_var1) < 0.000001) { return 0.0; } mid_var2 = (plan.D) + pt1[0] * (plan.A) + pt1[1] * (plan.B) + pt1[2] * (plan.C); t = 0.0 - mid_var2 / mid_var1; pt4[0] = pt1[0] + l * t; pt4[1] = pt1[1] + m * t; pt4[2] = pt1[2] + n * t; return ads_distance(pt0, pt4); } inline int XPoint::Modify(const Entity* pEntity) const { Entity ent = *pEntity; ent.SetData(10, &x); return ent.Modify(); } inline int XPoint::MakeEntity(const Entity* pEntity) const { Entity ent = *pEntity; Groups g(_T("*")); RBList ebuf = ads_entgetx(ent, (resbuf *)&g); ebuf.SetData(10, &x); return ads_entmake(ebuf); } int XPoint::Project(const XCircle* pCir, ads_point rp) const { //zjq 2009-08-31 ASSERT(pCir != NULL); XLine aLine(XPoint(x, y, pCir->m_ptCenter.z), pCir->m_ptCenter); XPoint pt1, pt2; if (aLine.Intersection(pCir, pt1, pt2) == 2) { if (ads_distance(&x, pt1) < ads_distance(&x, pt2)) { pt1 > rp; } else { pt2 > rp; } return RTNORM; } return RTERROR; } XPoint XPoint::Project(const XPlane* pPlan) const { ASSERT(pPlan != NULL); XPoint ptEnd = *this + XVector3D(pPlan->GetParaA(), pPlan->GetParaB(), pPlan->GetParaC()); XLine ln(*this, ptEnd); XPoint ptRet; VERIFY(pPlan->Intersect(ln, ptRet) != FALSE); return ptRet; } void XPoint::GetRotationMatrix(ads_real dRot, ads_matrix mat) const { ads_matrix matRot = { {cos(dRot), -sin(dRot), 0, 0}, {sin(dRot), cos(dRot), 0, 0}, {0, 0, 1, 0}, {0, 0, 0, 1} }; if (*this == XPoint()) { memcpy(mat, matRot, sizeof(matRot)); } else { ads_matrix matMov = { {1, 0, 0, -x}, {0, 1, 0, -y}, {0, 0, 1, -z}, {0, 0, 0, 1} }; ads_matrix matMov1 = { {1, 0, 0, x}, {0, 1, 0, y}, {0, 0, 1, z}, {0, 0, 0, 1} }; MatrixMultiply(mat, matMov1, matRot, matMov, NULL); } } void XPoint::GetScaleMatrix(ads_real nScale, ads_matrix mat) const { ads_matrix matScale = { {nScale, 0, 0, 0}, {0, nScale, 0, 0}, {0, 0, nScale, 0}, {0, 0, 0, 1} }; if (*this == XPoint()) { memcpy(mat, matScale, sizeof(ads_matrix)); } else { ads_matrix matMov = { {1, 0, 0, -x}, {0, 1, 0, -y}, {0, 0, 1, -z}, {0, 0, 0, 1} }; ads_matrix matMov1 = { {1, 0, 0, x}, {0, 1, 0, y}, {0, 0, 1, z}, {0, 0, 0, 1} }; MatrixMultiply(mat, matMov1, matScale, matMov, NULL); } } void XPoint::GetScaleMatrix(ads_real sx, ads_real sy, ads_real sz, ads_matrix mat) const { ads_matrix matScale = { {sx, 0, 0, 0}, {0, sy, 0, 0}, {0, 0, sz, 0}, {0, 0, 0, 1} }; if (*this == XPoint()) { memcpy(mat, matScale, sizeof(ads_matrix)); } else { ads_matrix matMov = { {1, 0, 0, -x}, {0, 1, 0, -y}, {0, 0, 1, -z}, {0, 0, 0, 1} }; ads_matrix matMov1 = { {1, 0, 0, x}, {0, 1, 0, y}, {0, 0, 1, z}, {0, 0, 0, 1} }; MatrixMultiply(mat, matMov1, matScale, matMov, NULL); } } void XPoint::GetMoveMatrix(const XPoint &ptDest, ads_matrix mat) const { XVector3D vt = ptDest - (*this); ads_matrix matMove = { {1, 0, 0, vt.x}, {0, 1, 0, vt.y}, {0, 0, 1, vt.z}, {0, 0, 0, 1} }; memcpy(mat, matMove, sizeof(ads_matrix)); } int XPoint::Make(const TCHAR *pszLay) const { TCHAR szLayer[80] = _T(""); if (pszLay) { _tcscpy(szLayer, pszLay); } else { xg_getvar(_T("clayer"), szLayer); } return XExport::MakeEntity(RTDXF0, _T("POINT"), 8, szLayer, 10, &x, NULL); }