Files
envi-code/SourceCode/Code2026/tg_shs/shs_geLib/TADSGePoint3d.cpp
T
gjm 164968b62e chore
把非utf8-bom编码的cpp/h文件改为 utf8 bom 编码, msvc识别utf8编码时,如果不是bom格式的,会使用当前cp_oem来解码.
2026-10-04 00:04:20 +08:00

328 lines
6.1 KiB
C++

//-----------------------------------------------------------------------------+
// Copyright (C), 1998-2007, Beijing Tangent Software Co. Ltd.
// = FileName : TADSGePoint3d 点类
// = Version : ver2.0
// = Author : wlw
// = CreateDate : 2002-09-09
// = Description: TADSGePoint3d 类定义
// = Maintainers:
//
//-----------------------------------------------------------------------------+
#include "StdAfx.h"
#include "TADSGePoint3d.h"
#include "TGGeCircle.h"
#include "TGGePlane.h"
#include "TGGeLine.h"
#include "TEntitySet.h"
#include "TGGePoly.h"
#include "TchGlobalFunc.h"
#include "TchPrivateGlobalFunc.h"
using namespace TchExport;
using namespace TchPrivate;
TADSGePoint3d::~TADSGePoint3d()
{
}
bool TADSGePoint3d::operator > (const TADSGePoint3d &pt) const
{
double dDis = x - pt.x;
if (dDis >TchGeLib::_DIST_SNAP)
{
return true;
}
else if (dDis < -TchGeLib::_DIST_SNAP)
{
return false;
}
else
{
dDis = y - pt.y;
if (dDis > TchGeLib::_DIST_SNAP)
{
return true;
}
else if (dDis < -TchGeLib::_DIST_SNAP)
{
return false;
}
else
{
return z-pt.z > TchGeLib::_DIST_SNAP;
}
}
}
inline int TADSGePoint3d::Project(const TGGeLine* pLine, ads_point rp) const
{
//lfy 2010-08-31 投影方法 发现AcGe 没有原方案快
ASSERT(pLine != NULL);
return PointProjectToLine(*this, pLine->StartPoint(), pLine->EndPoint(), rp);
/*AcGeLine3d lineT(pLine->StartPoint().AsAcGePoint3d(),pLine->EndPoint().AsAcGePoint3d());
AcGePointOnCurve3d ptOnCrv;
lineT.getClosestPointTo(asPnt3d(*this),ptOnCrv);
asPnt3d(rp) = ptOnCrv.point3d();
return RTNORM;*/
}
int TADSGePoint3d::Project(const AcGeLine3d* pLine,ads_point rp) const
{
//lfy 2010-08-31 投影发现AcGe 没有原方案快
//ASSERT(pLine != NULL);
//return PointProjectToLine(*this, pLine->, pLine->EndPoint(), rp);
ASSERT(pLine != NULL);
AcGePointOnCurve3d ptOnCrv;
pLine->getClosestPointTo(asPnt3d(*this),ptOnCrv);
asPnt3d(rp) = ptOnCrv.point3d();
return RTNORM;
}
inline double TADSGePoint3d::Distance(const TGGeLine* pLine) const
{
//lfy 2010-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 STPlanePara plan;
TVector3D 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 TADSGePoint3d::Modify(const TEntitySet* pEntity) const
{
TEntitySet ent = *pEntity;
ent.SetData(10, &x);
return ent.Modify();
}
inline int TADSGePoint3d::MakeEntity(const TEntitySet* pEntity) const
{
TEntitySet ent = *pEntity;
TGroups g(_T("*"));
TRBList ebuf = ads_entgetx(ent, (resbuf *)&g);
ebuf.SetData(10, &x);
return ads_entmake(ebuf);
}
int TADSGePoint3d::Project(const TGGeCircle* pCir, ads_point rp) const
{
//lfy 2010-08-31
ASSERT(pCir != NULL);
TGGeLine aLine(TADSGePoint3d(x, y, pCir->m_ptCenter.z), pCir->m_ptCenter);
TADSGePoint3d 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;
}
TADSGePoint3d TADSGePoint3d::Project(const TGGePlane* pPlan) const
{
ASSERT(pPlan != NULL);
TADSGePoint3d ptEnd = *this + TVector3D(pPlan->GetParaA(), pPlan->GetParaB(), pPlan->GetParaC());
TGGeLine ln(*this, ptEnd);
TADSGePoint3d ptRet;
VERIFY(pPlan->Intersect(ln, ptRet) == TRUE);
return ptRet;
}
void TADSGePoint3d::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 == TADSGePoint3d())
{
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 TADSGePoint3d::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 == TADSGePoint3d())
{
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 TADSGePoint3d::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 == TADSGePoint3d())
{
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 TADSGePoint3d::GetMoveMatrix(const TADSGePoint3d &ptDest, ads_matrix mat) const
{
TVector3D 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 TADSGePoint3d::Make(const TCHAR *pszLay) const
{
TCHAR szLayer[80] = _T("");
if (pszLay)
{
_tcscpy(szLayer, pszLay);
}
else
{
TGGetVar(_T("clayer"), szLayer);
}
return TchExport::MakeEntity(RTDXF0, _T("POINT"), 8, szLayer, 10, &x, NULL);
}