//-----------------------------------------------------------------------------+ // Copyright (C), 1998-2007, SH Software Co. Ltd. // = FileName : XPoint点类 // = Version : ver2.0 // = Author : zjq // = CreateDate : 2002-09-09 // = Description: XPoint类声明 // = Maintainers: // //-----------------------------------------------------------------------------+ #ifndef _XPOINT_H_ #define _XPOINT_H_ class XCircle; class XPlane; class XLine; class Entity; class GEOAPI XPoint { public: XPoint(const ads_point src); XPoint(const AcGePoint3d &src); XPoint(const AcGePoint2d &src); XPoint(const AcGeVector3d &src); XPoint(const AcGeVector2d &src); XPoint(const XPoint &ptFrom, double dDrt, double dDist); XPoint(ads_real dx = 0.0, ads_real dy = 0.0, ads_real dz = 0.0); ~XPoint(); XPoint& operator = (const AcGePoint3d &src); XPoint& operator = (const AcGePoint2d &src); XPoint& operator = (const AcGeVector3d &src); XPoint& operator = (const AcGeVector2d &src); XPoint& operator = (const XPoint & pt); XPoint& operator = (const ads_point pt); void operator > (ads_point pt) const; bool operator > (const XPoint &pt) const; bool operator < (const XPoint &pt)const; void operator += (const XPoint &pt); void operator -= (const XPoint &pt); void operator *= (double dScale); void operator /= (double dScale); bool operator == (const XPoint & pt) const; bool operator == (const ads_point pt) const; bool operator != (const XPoint &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 XLine* pLine, ads_point rp) const; int Project(const XCircle* pCir, ads_point rp) const; int Project(const AcGeLine3d* pLine,ads_point rp) const; XPoint Project(const XPlane* pPlan) const; double Distance(const XLine* pLine) const; double Distance(const XPoint& pt) const; double Distance2d(const XPoint& pt) const; double Distance(const XPoint& ptSta,const XPoint& ptEnd) const; void TransformBy(ads_matrix mat); void TransformBy(const AcGeMatrix3d& mat); XPoint 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 XPoint& ptDest, ads_matrix mat) const; void Mirror(const ads_point src, ads_point dest) const; void Mirror(const XPoint& ptSrc, XPoint& ptDest) const; void Rotate(ads_real dAng); void Reverse(); void Normalize(); int Make(LPCTSTR pszLay = NULL) const; int Modify(const Entity* pEntity) const; int MakeEntity(const Entity* 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 AT_xformpt(ads_matrix xform,ads_point pt,ads_point newpt) const; public: ads_real x,y,z; }; typedef class XPoint Point; typedef class XPoint Vector3D; typedef class XPoint XVector3D; inline XPoint::XPoint(ads_real dx, ads_real dy, ads_real dz) { x = dx; y = dy; z = dz; } inline XPoint::XPoint(const ads_point src) { x = src[0]; y = src[1]; z = src[2]; } inline XPoint::XPoint(const XPoint &ptFrom, double dDrt, double dDist) { ads_polar(ptFrom, dDrt, dDist, *this); } inline XPoint::XPoint(const AcGePoint3d &src) { x = src[0]; y = src[1]; z = src[2]; } inline XPoint::XPoint(const AcGePoint2d &src) { x = src[0]; y = src[1]; z = 0.0; } inline XPoint& XPoint::operator = (const AcGePoint3d &src) { x = src[0]; y = src[1]; z = src[2]; return *this; } inline XPoint& XPoint::operator = (const AcGePoint2d &src) { x = src[0]; y = src[1]; z = 0.0; return *this; } inline XPoint::XPoint(const AcGeVector3d &src) { x = src[0]; y = src[1]; z = src[2]; } inline XPoint::XPoint(const AcGeVector2d &src) { x = src[0]; y = src[1]; z = 0.0; } inline XPoint& XPoint::operator = (const AcGeVector3d &src) { x = src[0]; y = src[1]; z = src[2]; return *this; } inline XPoint& XPoint::operator = (const AcGeVector2d &src) { x = src[0]; y = src[1]; z = 0.0; return *this; } inline XPoint& XPoint::operator = (const XPoint & pt) { x = pt.x; y = pt.y; z = pt.z; return *this; } inline XPoint& XPoint::operator = (const ads_point pt) { x = pt[0]; y = pt[1]; z = pt[2]; return *this; } inline void XPoint::operator > (ads_point pt) const { pt[0] = x; pt[1] = y; pt[2] = z; } inline void XPoint::operator += (const XPoint &pt) { x += pt.x; y += pt.y; z += pt.z; } inline void XPoint::operator -= (const XPoint &pt) { x -= pt.x; y -= pt.y; z -= pt.z; } inline void XPoint::operator *= (double dScale) { x *= dScale; y *= dScale; z *= dScale; } inline void XPoint::operator /= (double dScale) { x /= dScale; y /= dScale; z /= dScale; } inline bool XPoint::operator == (const XPoint & pt) const { return (fabs(x - pt.x) < XGeLib::_DIST_SNAP && fabs(y - pt.y) < XGeLib::_DIST_SNAP && fabs(z - pt.z) < XGeLib::_DIST_SNAP); } inline bool XPoint::operator != (const XPoint &pt) const { return !((*this) == pt); } inline bool XPoint::operator == (const ads_point pt) const { return (ads_distance(&x, pt) < XGeLib::_DIST_SNAP); } inline bool XPoint::operator < (const XPoint &pt) const { return pt > (*this); } inline XPoint::operator ads_real*() const { return (ads_real *)&x; } inline XPoint::operator void* () const { return (void *)&x; } inline ads_real& XPoint::operator [] (int i) { return *(&x + i); } inline ads_real XPoint::operator [] (int i) const { return *(&x + i); } inline int XPoint::operator !() const { return (fabs(x) < 1E-6 && fabs(y) < 1E-6 && fabs(z) < 1E-6) ? 1 : 0; } inline double XPoint::Distance(const XPoint& 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 XPoint::Distance2d(const XPoint& pt) const { double XDis = x - pt.x; double YDis = y - pt.y; return sqrt(XDis * XDis + YDis * YDis); } inline void XPoint::TransformBy(const AcGeMatrix3d &mat) { ((AcGePoint3d *)this)->transformBy(mat); } inline void XPoint::AT_xformpt(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 XPoint XPoint::TransformAs(ads_matrix mat) const { XPoint pt; AT_xformpt(mat, (double *)&x, pt); return pt; } inline void XPoint::TransformBy(ads_matrix mat) { XPoint pt; AT_xformpt(mat, (double *)&x, pt); *this = pt; } inline void XPoint::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 XPoint::Mirror(const XPoint & src, XPoint &dest) const { dest.x = 2 * x - src.x; dest.y = 2 * y - src.y; dest.z = 2 * z - src.z; } inline void XPoint::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 XPoint::Reverse() { x = -x; y = -y; z = -z; } inline ads_real XPoint::Length() const { return sqrt(x * x + y * y + z * z); } inline void XPoint::Scale(ads_real dScale) { x *= dScale; y *= dScale; z *= dScale; } inline void XPoint::Normalize() { double nLen = Length(); if (nLen > 1.0E-9) { Scale(1.0 / nLen); } } inline XPoint::operator const AcGePoint3d & () { return *(const AcGePoint3d *)this; } inline XPoint::operator AcGePoint3d & () const { return *(AcGePoint3d *)this; } inline AcGePoint3d XPoint::AsAcGePoint3d() const { return AcGePoint3d(x, y, z); } inline XPoint::operator const AcGeVector3d& () { return *(const AcGeVector3d *)this; } inline XPoint::operator AcGeVector3d& () const { return *(AcGeVector3d *)this; } inline AcGeVector3d XPoint::AsAcGeVector3d() const { return AcGeVector3d(x, y, z); } inline XPoint::operator const AcGePoint2d& () { return *(const AcGePoint2d *)this; } inline XPoint::operator AcGePoint2d& () const { return *(AcGePoint2d *)this; } inline AcGePoint2d XPoint::AsAcGePoint2d() const { return AcGePoint2d(x, y); } inline XPoint::operator const AcGeVector2d& () { return *(const AcGeVector2d *)this; } inline XPoint::operator AcGeVector2d& () const { return *(AcGeVector2d *)this; } inline AcGeVector2d XPoint::AsAcGeVector2d() const { return AcGeVector2d(x, y); } inline double XPoint::Distance(const XPoint& ptSta,const XPoint& ptEnd) const { ads_real* pt0 = *this; ads_real* pt1 = ptSta; ads_real* pt2 = ptEnd; 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; double dist = ads_distance(pt0, pt4); return dist; } inline XPoint operator + (const XPoint & pt1, const XPoint & pt2) { return Point(pt1.x + pt2.x, pt1.y + pt2.y, pt1.z + pt2.z); } inline XPoint operator - (const XPoint & pt1, const XPoint & pt2) { return Point(pt1.x - pt2.x, pt1.y - pt2.y, pt1.z - pt2.z); } inline XPoint Max(const XPoint &pt1, const XPoint &pt2) { XPoint 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 XPoint Min(const XPoint &pt1, const XPoint &pt2) { XPoint 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