////////////////////////////////////////////////////////////////////////////// //文件 Point2D.h //主要功能: // 基础类库 //程序编写: 2005-12-07 ///////////////////////////////////////////////////////////////////////////// #pragma once #include "math.h" #define ZERO 1e-10 namespace NBase { class CSize8; class dfPoint; //class CPoint3D; class AFX_EXT_CLASS CPoint2D { public: CPoint2D(double xx, double yy); CPoint2D(const CPoint2D& pt); CPoint2D(const CSize8& st); CPoint2D(void); virtual ~CPoint2D(void); public: double x0,y0; public: CPoint2D operator +(const CPoint2D &point); CPoint2D operator /(const CPoint2D &point); void operator =(const CPoint2D &point); void operator =(const dfPoint &point); void operator =(const CPoint &point); void operator =(const CSize8 &sz); BOOL operator==(const CPoint2D &point); BOOL operator==(const CPoint2D &point) const; void operator +=(const CPoint2D& point); void operator -=(const CPoint2D& point); void operator *=(const CPoint2D& point); void operator /=(const CPoint2D& point); void operator +=(const double dist); void operator -=(const double dist); void operator *=(const double factor); void operator /=(const double den); virtual void Offset(double dx, double dy); virtual void ScaleCoor(double xs, double ys, double dx, double dy); virtual void Rotate(double xs, double ys, double angle); void SetPoint(double xx, double yy); void Rotate(double angle); double Distance(const CPoint2D& pt) const; double Dot(const CPoint2D& pt) const; CPoint2D Normalize() const; virtual double Abs() const; //xy平方和的根 virtual double squareAbs() const; //xy平方和 }; class AFX_EXT_CLASS CSize8 { public: CSize8(void); CSize8(double sx,double sy); CSize8(const CSize8& sz); CSize8(const CPoint2D& point); virtual ~CSize8(void); virtual void Serialize(CArchive& ar); void operator=(const CSize8& sz); void operator=(const CSize& sz); void operator=(const CPoint2D& point); BOOL operator==(const CSize8& sz); void operator +=(const CSize8& sz); void operator -=(const CSize8& sz); void operator +=(const double sz); void operator -=(const double sz); void SetSize(double sx, double sy); void ScaleSize(double sx, double sy); void Rotate(double angle); double cx; double cy; }; #define AXIS_X 1 #define AXIS_Y 2 #define AXIS_Z 3 class AFX_EXT_CLASS CPoint3D : public CPoint2D { public: CPoint3D(void); CPoint3D(double x, double y, double z); virtual ~CPoint3D(void); double z0; void Create(double x, double y, double z); void SetPoint(double x, double y, double z); double& operator[](int idx) { return idx!=0 ? (idx==1 ? y0 : z0) : x0; } double operator[](int idx) const { return idx!=0 ? (idx==1 ? y0 : z0) : x0; } CPoint3D operator+(const CPoint3D&) const; CPoint3D operator-(const CPoint3D&) const; CPoint3D operator*(double) const; CPoint3D operator/(double) const; void operator=(const CPoint3D& t); void operator=(const CPoint2D& t); void operator+=(const CPoint3D& t); void operator-=(const CPoint3D& t); void operator/=(const CPoint3D& t); void operator*=(const CPoint3D& t); void operator*=(double ds); double Distance2(CPoint3D& other); double Distance(CPoint3D& other); void Rotate(double angle, int nRotateAxis); void Rotate(double cosa,double sina, int nRotateAxis); void Rotate(double xm,double ym,double zm,double angle,int nRotateAxis); CPoint3D Cross(const CPoint3D& b) const; CPoint3D Normalize() const; double Dot(const CPoint3D& b) const; virtual double Abs() const; }; class AFX_EXT_CLASS CRect3D { public: CRect3D(void); ~CRect3D(void); void SetRect(CPoint3D ptMin, CPoint3D ptMax); CPoint3D CenterPoint(void); void NormalizeRect(void); double Width(void); //dx double Height(void); //dy double Depth(void); //dz void InflateRect(double x, double y, double z); void DeflateRect(double x, double y, double z); CPoint3D m_ptMin; CPoint3D m_ptMax; }; class AFX_EXT_CLASS dfPoint : public CPoint3D { public: dfPoint() :l(0), no(0) { } double l; int no; }; typedef CList CPointList; }; using namespace NBase; AFX_INLINE void CPoint2D::Offset(double dx, double dy) { x0 += dx; y0 += dy; } AFX_INLINE CPoint2D CPoint2D::operator +(const CPoint2D &point) { return CPoint2D(x0+point.x0, y0+point.y0); } AFX_INLINE CPoint2D CPoint2D::operator /(const CPoint2D &point) { return CPoint2D(x0/point.x0, y0/point.y0); } AFX_INLINE void CPoint2D::operator =(const CPoint2D &point) { x0 = point.x0; y0 = point.y0; } AFX_INLINE void CPoint2D::operator =(const dfPoint &point) { x0 = point.x0; y0 = point.y0; } AFX_INLINE void CPoint2D::operator =(const CPoint &point) { x0 = point.x; y0 = point.y; } AFX_INLINE void CPoint2D::operator =(const CSize8 &sz) { x0=sz.cx; y0=sz.cy; } AFX_INLINE void CPoint2D::SetPoint(double xx, double yy) { x0 = xx; y0 = yy; } AFX_INLINE BOOL CPoint2D::operator==(const CPoint2D& point) { if(fabs(x0-point.x0)