|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
//<2F>ļ<EFBFBD> Point2D.h
|
|
|
|
|
|
//<2F><>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD>:
|
|
|
|
|
|
// <09><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>д: 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ƽ<79><C6BD><EFBFBD>͵ĸ<CDB5>
|
|
|
|
|
|
virtual double squareAbs() const; //xyƽ<79><C6BD><EFBFBD><EFBFBD>
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
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<dfPoint, dfPoint> 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)<ZERO && fabs(y0-point.y0)<ZERO) return TRUE;
|
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
AFX_INLINE BOOL CPoint2D::operator==(const CPoint2D& point) const
|
|
|
|
|
|
{
|
|
|
|
|
|
if(fabs(x0-point.x0)<ZERO && fabs(y0-point.y0)<ZERO) return TRUE;
|
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
AFX_INLINE void CSize8::SetSize(double sx, double sy)
|
|
|
|
|
|
{
|
|
|
|
|
|
cx=sx;
|
|
|
|
|
|
cy=sy;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
AFX_INLINE void CSize8::operator=(const CSize8& sz)
|
|
|
|
|
|
{
|
|
|
|
|
|
cx=sz.cx;
|
|
|
|
|
|
cy=sz.cy;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
AFX_INLINE void CSize8::operator=(const CPoint2D& point)
|
|
|
|
|
|
{
|
|
|
|
|
|
cx=point.x0;
|
|
|
|
|
|
cy=point.y0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
AFX_INLINE void CSize8::operator=(const CSize& sz)
|
|
|
|
|
|
{
|
|
|
|
|
|
cx=sz.cx;
|
|
|
|
|
|
cy=sz.cy;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
AFX_INLINE BOOL CSize8::operator==(const CSize8& sz)
|
|
|
|
|
|
{
|
|
|
|
|
|
if(fabs(cx-sz.cx)<ZERO && fabs(cy-sz.cy)<ZERO) return TRUE;
|
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
AFX_INLINE void CSize8::operator +=(const CSize8& sz)
|
|
|
|
|
|
{
|
|
|
|
|
|
cx+=sz.cx;
|
|
|
|
|
|
cy+=sz.cy;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
AFX_INLINE void CSize8::operator -=(const CSize8& sz)
|
|
|
|
|
|
{
|
|
|
|
|
|
cx-=sz.cx;
|
|
|
|
|
|
cy-=sz.cy;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
AFX_INLINE void CSize8::operator +=(const double sz)
|
|
|
|
|
|
{
|
|
|
|
|
|
cx+=sz;
|
|
|
|
|
|
cy+=sz;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
AFX_INLINE void CSize8::operator -=(const double sz)
|
|
|
|
|
|
{
|
|
|
|
|
|
cx-=sz;
|
|
|
|
|
|
cy-=sz;
|
|
|
|
|
|
}
|