Files
envi-code/SourceCode/Code2026/tg_shs/inc/geo/TADSGePoint3d.h
T
2026-09-28 15:28:50 +08:00

550 lines
11 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:
//
//-----------------------------------------------------------------------------+
#ifndef _TADSGEPOINT3D_H_
#define _TADSGEPOINT3D_H_
class TGGeCircle;
class TGGePlane;
class TGGeLine;
class TEntitySet;
class GEOAPI TADSGePoint3d
{
public:
TADSGePoint3d(const ads_point src);
TADSGePoint3d(const AcGePoint3d &src);
TADSGePoint3d(const AcGePoint2d &src);
TADSGePoint3d(const AcGeVector3d &src);
TADSGePoint3d(const AcGeVector2d &src);
TADSGePoint3d(const TADSGePoint3d &ptFrom, double dDrt, double dDist);
TADSGePoint3d(ads_real dx = 0.0, ads_real dy = 0.0, ads_real dz = 0.0);
~TADSGePoint3d();
TADSGePoint3d& operator = (const AcGePoint3d &src);
TADSGePoint3d& operator = (const AcGePoint2d &src);
TADSGePoint3d& operator = (const AcGeVector3d &src);
TADSGePoint3d& operator = (const AcGeVector2d &src);
TADSGePoint3d& operator = (const TADSGePoint3d & pt);
TADSGePoint3d& operator = (const ads_point pt);
void operator > (ads_point pt) const;
bool operator > (const TADSGePoint3d &pt) const;
bool operator < (const TADSGePoint3d &pt)const;
void operator += (const TADSGePoint3d &pt);
void operator -= (const TADSGePoint3d &pt);
void operator *= (double dScale);
void operator /= (double dScale);
bool operator == (const TADSGePoint3d & pt) const;
bool operator == (const ads_point pt) const;
bool operator != (const TADSGePoint3d &pt) const;
operator ads_real* () const;
operator void* () const;
ads_real& operator [] (int i);
ads_real operator [] (int i) const;
int operator ! () const;
//3D属性;
//把当前点往线上投影, rp--结果
int Project(const TGGeLine* pLine, ads_point rp) const;
int Project(const TGGeCircle* pCir, ads_point rp) const;
int Project(const AcGeLine3d* pLine,ads_point rp) const;
TADSGePoint3d Project(const TGGePlane* pPlan) const;
double Distance(const TGGeLine* pLine) const;
double Distance(const TADSGePoint3d& pt) const;
double Distance2d(const TADSGePoint3d& pt) const;
double Distance(const TADSGePoint3d& ptSta,const TADSGePoint3d& ptEnd) const;
void TransformBy(ads_matrix mat);
void TransformBy(const AcGeMatrix3d& mat);
TADSGePoint3d TransformAs(ads_matrix mat) const;
void GetRotationMatrix(ads_real dRot, ads_matrix mat) const;
void GetScaleMatrix(ads_real dScale, ads_matrix mat) const;
void GetScaleMatrix(ads_real sx, ads_real sy, ads_real sz, ads_matrix mat) const;
void GetMoveMatrix(const TADSGePoint3d& ptDest, ads_matrix mat) const;
void Mirror(const ads_point src, ads_point dest) const;
void Mirror(const TADSGePoint3d& ptSrc, TADSGePoint3d& ptDest) const;
void Rotate(ads_real dAng);
void Reverse();
void Normalize();
int Make(LPCTSTR pszLay = NULL) const;
int Modify(const TEntitySet* pEntity) const;
int MakeEntity(const TEntitySet* pEntity) const;
ads_real Length() const;
void Scale(ads_real dScale);
operator const AcGePoint3d & ();
operator AcGePoint3d & () const;
AcGePoint3d AsAcGePoint3d() const;
operator const AcGeVector3d & ();
operator AcGeVector3d & () const;
AcGeVector3d AsAcGeVector3d() const;
operator const AcGePoint2d & ();
operator AcGePoint2d & () const;
AcGePoint2d AsAcGePoint2d() const;
operator const AcGeVector2d & ();
operator AcGeVector2d & () const;
AcGeVector2d AsAcGeVector2d() const;
void PointTransformBy(ads_matrix xform,ads_point pt,ads_point newpt) const;
public:
ads_real x,y,z;
};
typedef class TADSGePoint3d Point;
typedef class TADSGePoint3d Vector3D;
typedef class TADSGePoint3d TVector3D;
inline TADSGePoint3d::TADSGePoint3d(ads_real dx, ads_real dy, ads_real dz)
{
x = dx;
y = dy;
z = dz;
}
inline TADSGePoint3d::TADSGePoint3d(const ads_point src)
{
x = src[0];
y = src[1];
z = src[2];
}
inline TADSGePoint3d::TADSGePoint3d(const TADSGePoint3d &ptFrom, double dDrt, double dDist)
{
ads_polar(ptFrom, dDrt, dDist, *this);
}
inline TADSGePoint3d::TADSGePoint3d(const AcGePoint3d &src)
{
x = src[0];
y = src[1];
z = src[2];
}
inline TADSGePoint3d::TADSGePoint3d(const AcGePoint2d &src)
{
x = src[0];
y = src[1];
z = 0.0;
}
inline TADSGePoint3d& TADSGePoint3d::operator = (const AcGePoint3d &src)
{
x = src[0];
y = src[1];
z = src[2];
return *this;
}
inline TADSGePoint3d& TADSGePoint3d::operator = (const AcGePoint2d &src)
{
x = src[0];
y = src[1];
z = 0.0;
return *this;
}
inline TADSGePoint3d::TADSGePoint3d(const AcGeVector3d &src)
{
x = src[0];
y = src[1];
z = src[2];
}
inline TADSGePoint3d::TADSGePoint3d(const AcGeVector2d &src)
{
x = src[0];
y = src[1];
z = 0.0;
}
inline TADSGePoint3d& TADSGePoint3d::operator = (const AcGeVector3d &src)
{
x = src[0];
y = src[1];
z = src[2];
return *this;
}
inline TADSGePoint3d& TADSGePoint3d::operator = (const AcGeVector2d &src)
{
x = src[0];
y = src[1];
z = 0.0;
return *this;
}
inline TADSGePoint3d& TADSGePoint3d::operator = (const TADSGePoint3d & pt)
{
x = pt.x;
y = pt.y;
z = pt.z;
return *this;
}
inline TADSGePoint3d& TADSGePoint3d::operator = (const ads_point pt)
{
x = pt[0];
y = pt[1];
z = pt[2];
return *this;
}
inline void TADSGePoint3d::operator > (ads_point pt) const
{
pt[0] = x;
pt[1] = y;
pt[2] = z;
}
inline void TADSGePoint3d::operator += (const TADSGePoint3d &pt)
{
x += pt.x;
y += pt.y;
z += pt.z;
}
inline void TADSGePoint3d::operator -= (const TADSGePoint3d &pt)
{
x -= pt.x;
y -= pt.y;
z -= pt.z;
}
inline void TADSGePoint3d::operator *= (double dScale)
{
x *= dScale;
y *= dScale;
z *= dScale;
}
inline void TADSGePoint3d::operator /= (double dScale)
{
x /= dScale;
y /= dScale;
z /= dScale;
}
inline bool TADSGePoint3d::operator == (const TADSGePoint3d & pt) const
{
return (fabs(x - pt.x) < TchGeLib::_DIST_SNAP && fabs(y - pt.y) < TchGeLib::_DIST_SNAP && fabs(z - pt.z) < TchGeLib::_DIST_SNAP);
}
inline bool TADSGePoint3d::operator != (const TADSGePoint3d &pt) const
{
return !((*this) == pt);
}
inline bool TADSGePoint3d::operator == (const ads_point pt) const
{
return (ads_distance(&x, pt) < TchGeLib::_DIST_SNAP);
}
inline bool TADSGePoint3d::operator < (const TADSGePoint3d &pt) const
{
return pt > (*this);
}
inline TADSGePoint3d::operator ads_real*() const
{
return (ads_real *)&x;
}
inline TADSGePoint3d::operator void* () const
{
return (void *)&x;
}
inline ads_real& TADSGePoint3d::operator [] (int i)
{
return *(&x + i);
}
inline ads_real TADSGePoint3d::operator [] (int i) const
{
return *(&x + i);
}
inline int TADSGePoint3d::operator !() const
{
return (fabs(x) < 1E-6 && fabs(y) < 1E-6 && fabs(z) < 1E-6) ? 1 : 0;
}
inline double TADSGePoint3d::Distance(const TADSGePoint3d& pt) const
{
double t1 = pt.x - x;
double t2 = pt.y - y;
double t3 = pt.z - z;
return sqrt(t1 * t1 + t2 * t2 + t3 * t3);
}
inline double TADSGePoint3d::Distance2d(const TADSGePoint3d& pt) const
{
double XDis = x - pt.x;
double YDis = y - pt.y;
return sqrt(XDis * XDis + YDis * YDis);
}
inline void TADSGePoint3d::TransformBy(const AcGeMatrix3d &mat)
{
((AcGePoint3d *)this)->transformBy(mat);
}
inline void TADSGePoint3d::PointTransformBy(ads_matrix xform,ads_point pt,ads_point newpt) const
{
int i,j;
ads_point pt0;
newpt[X] = newpt[Y] = newpt[Z] = 0.0;
Cpoint(pt0, pt);
for (i = X; i <= Z; i++)
{
for (j = X; j <= Z; j++)
{
newpt[i] += xform[i][j] * pt0[j];
}
newpt[i] += xform[i][T];
}
}
inline TADSGePoint3d TADSGePoint3d::TransformAs(ads_matrix mat) const
{
TADSGePoint3d pt;
PointTransformBy(mat, (double *)&x, pt);
return pt;
}
inline void TADSGePoint3d::TransformBy(ads_matrix mat)
{
TADSGePoint3d pt;
PointTransformBy(mat, (double *)&x, pt);
*this = pt;
}
inline void TADSGePoint3d::Mirror(const ads_point src, ads_point dest) const
{
dest[0] = 2 * x - src[0];
dest[1] = 2 * y - src[1];
dest[2] = 2 * z - src[2];
}
inline void TADSGePoint3d::Mirror(const TADSGePoint3d & src, TADSGePoint3d &dest) const
{
dest.x = 2 * x - src.x;
dest.y = 2 * y - src.y;
dest.z = 2 * z - src.z;
}
inline void TADSGePoint3d::Rotate(ads_real dang)
{
ads_real dewX = x * cos(dang) - y * sin(dang);
ads_real dewY = x * sin(dang) + y * cos(dang);
x = dewX;
y = dewY;
}
inline void TADSGePoint3d::Reverse()
{
x = -x;
y = -y;
z = -z;
}
inline ads_real TADSGePoint3d::Length() const
{
return sqrt(x * x + y * y + z * z);
}
inline void TADSGePoint3d::Scale(ads_real dScale)
{
x *= dScale;
y *= dScale;
z *= dScale;
}
inline void TADSGePoint3d::Normalize()
{
double nLen = Length();
if (nLen > 1.0E-9)
{
Scale(1.0 / nLen);
}
}
inline TADSGePoint3d::operator const AcGePoint3d & ()
{
return *(const AcGePoint3d *)this;
}
inline TADSGePoint3d::operator AcGePoint3d & () const
{
return *(AcGePoint3d *)this;
}
inline AcGePoint3d TADSGePoint3d::AsAcGePoint3d() const
{
return AcGePoint3d(x, y, z);
}
inline TADSGePoint3d::operator const AcGeVector3d& ()
{
return *(const AcGeVector3d *)this;
}
inline TADSGePoint3d::operator AcGeVector3d& () const
{
return *(AcGeVector3d *)this;
}
inline AcGeVector3d TADSGePoint3d::AsAcGeVector3d() const
{
return AcGeVector3d(x, y, z);
}
inline TADSGePoint3d::operator const AcGePoint2d& ()
{
return *(const AcGePoint2d *)this;
}
inline TADSGePoint3d::operator AcGePoint2d& () const
{
return *(AcGePoint2d *)this;
}
inline AcGePoint2d TADSGePoint3d::AsAcGePoint2d() const
{
return AcGePoint2d(x, y);
}
inline TADSGePoint3d::operator const AcGeVector2d& ()
{
return *(const AcGeVector2d *)this;
}
inline TADSGePoint3d::operator AcGeVector2d& () const
{
return *(AcGeVector2d *)this;
}
inline AcGeVector2d TADSGePoint3d::AsAcGeVector2d() const
{
return AcGeVector2d(x, y);
}
inline double TADSGePoint3d::Distance(const TADSGePoint3d& ptSta,const TADSGePoint3d& ptEnd) const
{
ads_real* pt0 = *this;
ads_real* pt1 = ptSta;
ads_real* pt2 = ptEnd;
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;
double dist = ads_distance(pt0, pt4);
return dist;
}
inline TADSGePoint3d operator + (const TADSGePoint3d & pt1, const TADSGePoint3d & pt2)
{
return Point(pt1.x + pt2.x, pt1.y + pt2.y, pt1.z + pt2.z);
}
inline TADSGePoint3d operator - (const TADSGePoint3d & pt1, const TADSGePoint3d & pt2)
{
return Point(pt1.x - pt2.x, pt1.y - pt2.y, pt1.z - pt2.z);
}
inline TADSGePoint3d Max(const TADSGePoint3d &pt1, const TADSGePoint3d &pt2)
{
TADSGePoint3d upPt;
upPt.x = max(pt1.x, pt2.x);
upPt.y = max(pt1.y, pt2.y);
upPt.z = max(pt1.z, pt2.z);
return upPt;
}
inline TADSGePoint3d Min(const TADSGePoint3d &pt1, const TADSGePoint3d &pt2)
{
TADSGePoint3d lowPt;
lowPt.x = min(pt1.x, pt2.x);
lowPt.y = min(pt1.y, pt2.y);
lowPt.z = min(pt1.z, pt2.z);
return lowPt;
}
#endif