⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cadbase.cpp

📁 这是一个程序的一般架构方法
💻 CPP
📖 第 1 页 / 共 4 页
字号:
//-- {CycleCode: 532} file [0..28316]
//-- {AddDecl: 533} module.includes preserve=yes [0..419]
//## begin module.includes preserve=yes

#include "stdafx.h"

#include "cadbase.h"
#include "math.h"

/***********************************************************************************
/
/   CLASS NAME: CPoint2D
/	CLASS DESCRIPATION: Designed for 2 dimensional point
/   CREATED BY: Olive Wang in Apr.28,2000
/   MODIFIED BY:
*************************************************************************************/

// constructor && destructor
//## end module.includes preserve=yes
//-- {AddDecl: 534} region.unprotectedFunction [420..463]
CPoint2D::CPoint2D()
{
//## begin CPoint2D::CPoint2D%3A7812EBFEED.body preserve=yes
	x=0.0;
	y=0.0;
//## end CPoint2D::CPoint2D%3A7812EBFEED.body
}
//-- {AddDecl: 535} region.unprotectedFunction [464..532]

CPoint2D::CPoint2D(double ix,double iy)
{
//## begin CPoint2D::CPoint2D%9B4E6C01FEED.body preserve=yes
	x = ix;
	y = iy;
//## end CPoint2D::CPoint2D%9B4E6C01FEED.body
}
//-- {AddDecl: 536} region.unprotectedFunction [533..596]

CPoint2D::CPoint2D(const double*p)
{
//## begin CPoint2D::CPoint2D%32EE47F3FEED.body preserve=yes
	x=p[0];
	y=p[1];
//## end CPoint2D::CPoint2D%32EE47F3FEED.body
}
//-- {AddDecl: 537} region.unprotectedFunction [597..653]

CPoint2D::CPoint2D(POINT2D p)
{
//## begin CPoint2D::CPoint2D%C0222955FEED.body preserve=yes
	x=p.x;
	y=p.y;
//## end CPoint2D::CPoint2D%C0222955FEED.body
}
//-- {AddDecl: 538} region.unprotectedFunction [654..684]

CPoint2D::~CPoint2D()
{
//## begin CPoint2D::~CPoint2D%A7674136FEED.body preserve=yes
//## end CPoint2D::~CPoint2D%A7674136FEED.body
}
//-- {AddDecl: 539} region.unprotectedFunction [685..803]


// offsetting with vector
CPoint2D CPoint2D::operator+(VECTOR2D v) const
{
//## begin CPoint2D::operator +%CDBC16A2FEED.body preserve=yes
	return CPoint2D(x+v.dx,y+v.dy);
//## end CPoint2D::operator +%CDBC16A2FEED.body
}
//-- {AddDecl: 540} region.unprotectedFunction [804..872]

void CPoint2D::operator+=(VECTOR2D v)
{
//## begin CPoint2D::operator +=%45A3FC8DFEED.body preserve=yes
	x+=v.dx;
	y+=v.dy;
//## end CPoint2D::operator +=%45A3FC8DFEED.body
}
//-- {AddDecl: 541} region.unprotectedFunction [873..962]

CPoint2D CPoint2D::operator-(VECTOR2D v) const
{
//## begin CPoint2D::operator -%93FAF223FEED.body preserve=yes
	return CPoint2D(x-v.dx,y-v.dy);
//## end CPoint2D::operator -%93FAF223FEED.body
}
//-- {AddDecl: 542} region.unprotectedFunction [963..1031]

void CPoint2D::operator-=(VECTOR2D v)
{
//## begin CPoint2D::operator -=%EA2C608AFEED.body preserve=yes
	x+=v.dx;
	y+=v.dy;
//## end CPoint2D::operator -=%EA2C608AFEED.body
}
//-- {AddDecl: 543} region.unprotectedFunction [1032..1161]


// derive vector = this point - sp
CVector2D CPoint2D::operator-(POINT2D sp) const
{
//## begin CPoint2D::operator -%2D9D5029FEED.body preserve=yes
	return CVector2D(x-sp.x,y-sp.y);
//## end CPoint2D::operator -%2D9D5029FEED.body
}
//-- {AddDecl: 544} region.unprotectedFunction [1162..1499]

// transform the point
CPoint2D CPoint2D::operator*(const MATRIX2D& matrix) const
{
//## begin CPoint2D::operator *%785954FDFEED.body preserve=yes
	double xx,yy,sc;
	xx = x*matrix.A[0][0]+y*matrix.A[1][0] + matrix.A[2][0];
	yy = x*matrix.A[0][1]+y*matrix.A[1][1] + matrix.A[2][1];
	sc = x*matrix.A[0][2]+y*matrix.A[1][2] + matrix.A[2][2];
	xx /= sc;
	yy /= sc;
	return CPoint2D(xx,yy);
//## end CPoint2D::operator *%785954FDFEED.body
}
//-- {AddDecl: 545} region.unprotectedFunction [1500..1706]

BOOL CPoint2D::operator==(const CPoint2D Po2D)
{
//## begin CPoint2D::operator ==%63D4E47CFEED.body preserve=yes
	if (fabs(Po2D.x - x) > MAX_ZORE_DOUBLE)
	{
		return FALSE;
	}
	if (fabs(Po2D.y - y) > MAX_ZORE_DOUBLE)
	{
		return FALSE;
	}
	return TRUE;
//## end CPoint2D::operator ==%63D4E47CFEED.body
}
//-- {AddDecl: 546} region.unprotectedFunction [1707..1792]

void  CPoint2D::operator*=(const MATRIX2D& matrix)
{
//## begin CPoint2D::operator *=%AD9C1D52FEED.body preserve=yes
	(*this)=(*this)*matrix;
//## end CPoint2D::operator *=%AD9C1D52FEED.body
}
//-- {InsertRegion: 692} module.vulnerableDeclarations [1793..2155]
//## begin module.additionalDeclarations preserve=yes
/**********************************************************************************
//
//     CLASS NAME: CVector2D
//     DESCRIPTION: designed for 2 dimensional vector
//     CREATED BY: Olive Wang in April 28,2000
//     MODIFIED BY:
//
***********************************************************************************/
// constructor&&destructor
//## end module.additionalDeclarations
//-- {AddDecl: 547} region.unprotectedFunction [2156..2203]
CVector2D::CVector2D()
{
//## begin CVector2D::CVector2D%686A3901FEED.body preserve=yes
	dx=0.0;
	dy=0.0;
//## end CVector2D::CVector2D%686A3901FEED.body
}
//-- {AddDecl: 548} region.unprotectedFunction [2204..2272]

CVector2D::CVector2D(double ix,double iy)
{
//## begin CVector2D::CVector2D%19EDF2EBFEED.body preserve=yes
	dx=ix;
	dy=iy;
//## end CVector2D::CVector2D%19EDF2EBFEED.body
}
//-- {AddDecl: 549} region.unprotectedFunction [2273..2344]

CVector2D::CVector2D(const double* pv)
{
//## begin CVector2D::CVector2D%4D35DEE2FEED.body preserve=yes
	dx=pv[0];
	dy=pv[1];
//## end CVector2D::CVector2D%4D35DEE2FEED.body
}
//-- {AddDecl: 550} region.unprotectedFunction [2345..2409]

CVector2D::CVector2D(VECTOR2D v)
{
//## begin CVector2D::CVector2D%E6D14E5CFEED.body preserve=yes
	
	dx=v.dx;
	dy=v.dy;
//## end CVector2D::CVector2D%E6D14E5CFEED.body
}
//-- {AddDecl: 551} region.unprotectedFunction [2410..2442]

CVector2D::~CVector2D()
{
//## begin CVector2D::~CVector2D%C8A1327FFEED.body preserve=yes
//## end CVector2D::~CVector2D%C8A1327FFEED.body
}
//-- {AddDecl: 552} region.unprotectedFunction [2443..2537]

CVector2D CVector2D::operator+(VECTOR2D v) const
{
//## begin CVector2D::operator +%18050FA6FEED.body preserve=yes
	return CVector2D(dx+v.dx,dy+v.dy);
//## end CVector2D::operator +%18050FA6FEED.body
}
//-- {AddDecl: 553} region.unprotectedFunction [2538..2632]

CVector2D CVector2D::operator-(VECTOR2D v) const
{
//## begin CVector2D::operator -%161E609AFEED.body preserve=yes
	return CVector2D(dx-v.dx,dy-v.dy);
//## end CVector2D::operator -%161E609AFEED.body
}
//-- {AddDecl: 554} region.unprotectedFunction [2633..2708]

void CVector2D::operator+=(VECTOR2D v)
{
//## begin CVector2D::operator +=%08940E05FEED.body preserve=yes
	dx += v.dx;
	dy += v.dy;
//## end CVector2D::operator +=%08940E05FEED.body
}
//-- {AddDecl: 555} region.unprotectedFunction [2709..2780]

void CVector2D::operator-=(VECTOR2D v)
{
//## begin CVector2D::operator -=%A8DFA3D1FEED.body preserve=yes
	dx-=v.dx;
	dy-=v.dy;
//## end CVector2D::operator -=%A8DFA3D1FEED.body
}
//-- {AddDecl: 556} region.unprotectedFunction [2781..2867]

CVector2D CVector2D::operator*(double d) const
{
//## begin CVector2D::operator *%D8443131FEED.body preserve=yes
	return CVector2D(dx*d,dy*d);
//## end CVector2D::operator *%D8443131FEED.body
}
//-- {AddDecl: 557} region.unprotectedFunction [2868..2935]

void CVector2D::operator*=(double d)
{
//## begin CVector2D::operator *=%BB279C88FEED.body preserve=yes
	dx *= d;
	dy *= d;
//## end CVector2D::operator *=%BB279C88FEED.body
}
//-- {AddDecl: 558} region.unprotectedFunction [2936..3022]

CVector2D CVector2D::operator/(double d) const
{
//## begin CVector2D::operator /%01CB38BCFEED.body preserve=yes
	return CVector2D(dx/d,dy/d);
//## end CVector2D::operator /%01CB38BCFEED.body
}
//-- {AddDecl: 559} region.unprotectedFunction [3023..3091]
	
void CVector2D::operator/=(double d)
{
//## begin CVector2D::operator /=%288185B2FEED.body preserve=yes
	dx /= d;
	dy /= d;
//## end CVector2D::operator /=%288185B2FEED.body
}
//-- {AddDecl: 560} region.unprotectedFunction [3092..3212]

// cross product
CVector3D CVector2D::operator*(VECTOR2D v) const
{
//## begin CVector2D::operator *%FF78C592FEED.body preserve=yes
	return CVector3D(0.0,0.0,dx*v.dy-v.dx*dy);
//## end CVector2D::operator *%FF78C592FEED.body
}
//-- {AddDecl: 561} region.unprotectedFunction [3213..3310]
	
// dot product
double CVector2D::operator|(VECTOR2D v) const
{
//## begin CVector2D::operator |%F149BD83FEED.body preserve=yes
	return dx*v.dx+dy*v.dy;
//## end CVector2D::operator |%F149BD83FEED.body
}
//-- {AddDecl: 562} region.unprotectedFunction [3311..3646]


//matrix transform
CVector2D CVector2D::operator*(const MATRIX2D& matrix) const
{
//## begin CVector2D::operator *%76F3639BFEED.body preserve=yes
	double x,y,sc;
	x = dx*matrix.A[0][0]+dy*matrix.A[1][0] + matrix.A[2][0];
	y = dx*matrix.A[0][1]+dy*matrix.A[1][1] + matrix.A[2][1];
	sc= dx*matrix.A[0][2]+dy*matrix.A[1][2] + matrix.A[2][2];
	x /= sc;
	y /= sc;
	return CVector2D(x,y);
//## end CVector2D::operator *%76F3639BFEED.body
}
//-- {AddDecl: 563} region.unprotectedFunction [3647..3732]

void CVector2D::operator*=(const MATRIX2D& matrix)
{
//## begin CVector2D::operator *=%0758FA18FEED.body preserve=yes
	(*this)=(*this)*matrix;
//## end CVector2D::operator *=%0758FA18FEED.body
}
//-- {AddDecl: 564} region.unprotectedFunction [3733..3805]

double CVector2D::GetLength() const
{
//## begin CVector2D::GetLength%7858B291FEED.body preserve=yes
	return sqrt(dx*dx+dy*dy);
//## end CVector2D::GetLength%7858B291FEED.body
}
//-- {AddDecl: 565} region.unprotectedFunction [3806..3916]

CVector2D CVector2D::GetNormal() const
{
//## begin CVector2D::GetNormal%D51ADB9DFEED.body preserve=yes
	double len = GetLength();
	return CVector2D(dx/len,dy/len);
//## end CVector2D::GetNormal%D51ADB9DFEED.body
}
//-- {AddDecl: 566} region.unprotectedFunction [3917..4011]

void CVector2D::Normalize()
{
//## begin CVector2D::Normalize%9D42C6E7FEED.body preserve=yes
	double len = GetLength();
	dx = dx/len;
	dy = dy/len;
//## end CVector2D::Normalize%9D42C6E7FEED.body
}
//-- {AddDecl: 567} region.unprotectedFunction [4012..4088]

BOOL CVector2D::IsZeroLength() const
{
//## begin CVector2D::IsZeroLength%49AA9F06FEED.body preserve=yes
	return IS_ZERO(GetLength());
//## end CVector2D::IsZeroLength%49AA9F06FEED.body
}
//-- {InsertRegion: 693} module.vulnerableDeclarations [4089..4444]
//## begin module.additionalDeclarations preserve=yes

/***********************************************************************************
/
/   CLASS NAME: CPoint3D
/	CLASS DESCRIPATION: Designed for 2 dimensional point
/   CREATED BY: Olive Wang in Apr.28,2000
/   MODIFIED BY:
*************************************************************************************/

// constructor && destructor
//## end module.additionalDeclarations
//-- {AddDecl: 568} region.unprotectedFunction [4445..4501]
CPoint3D::CPoint3D()
{
//## begin CPoint3D::CPoint3D%D358D7DDFEED.body preserve=yes
	x=0.0;
	y=0.0;
	z=99999.0;
//## end CPoint3D::CPoint3D%D358D7DDFEED.body
}
//-- {AddDecl: 569} region.unprotectedFunction [4502..4591]

CPoint3D::CPoint3D(double ix,double iy,double iz)
{
//## begin CPoint3D::CPoint3D%DD08228DFEED.body preserve=yes
	x = ix;
	y = iy;
	z = iz;
//## end CPoint3D::CPoint3D%DD08228DFEED.body
}
//-- {AddDecl: 570} region.unprotectedFunction [4592..4663]
CPoint3D::CPoint3D(const double*p)
{
//## begin CPoint3D::CPoint3D%1848D97AFEED.body preserve=yes
	x=p[0];
	y=p[1];
	z=p[2];
//## end CPoint3D::CPoint3D%1848D97AFEED.body
}
//-- {AddDecl: 571} region.unprotectedFunction [4664..4729]

CPoint3D::CPoint3D(POINT3D p)
{
//## begin CPoint3D::CPoint3D%86081502FEED.body preserve=yes
	x=p.x;
	y=p.y;
	z=p.z;
//## end CPoint3D::CPoint3D%86081502FEED.body
}
//-- {AddDecl: 572} region.unprotectedFunction [4730..4760]

CPoint3D::~CPoint3D()
{
//## begin CPoint3D::~CPoint3D%9B5F1A3DFEED.body preserve=yes
//## end CPoint3D::~CPoint3D%9B5F1A3DFEED.body
}
//-- {AddDecl: 573} region.unprotectedFunction [4761..5272]

//operators
CPoint3D CPoint3D::operator*(const MATRIX3D& matrix) const
{
//## begin CPoint3D::operator *%E520C14EFEED.body preserve=yes
	double rx,ry,rz,sc;
	rx = x * matrix.A[0][0] + y * matrix.A[1][0] + z * matrix.A[2][0] + matrix.A[3][0];
	ry = x * matrix.A[0][1] + y * matrix.A[1][1] + z * matrix.A[2][1] + matrix.A[3][1];
	rz = x * matrix.A[0][2] + y * matrix.A[1][2] + z * matrix.A[2][2] + matrix.A[3][2];
	sc = x * matrix.A[0][3] + y * matrix.A[1][3] + z * matrix.A[2][3] + matrix.A[3][3];
	rx /= sc;
	ry /= sc;
	rz /= sc;
	return CPoint3D(rx,ry,rz);
//## end CPoint3D::operator *%E520C14EFEED.body
}
//-- {AddDecl: 574} region.unprotectedFunction [5273..5360]

void  CPoint3D::operator*=(const MATRIX3D& matrix)
{
//## begin CPoint3D::operator *=%EDB62837FEED.body preserve=yes
	(*this) = (*this)*matrix;
//## end CPoint3D::operator *=%EDB62837FEED.body
}
//-- {AddDecl: 575} region.unprotectedFunction [5361..5451]
void  CPoint3D::operator=(CPoint2D Po2D)
{
//## begin CPoint3D::operator =%967A30B5FEED.body preserve=yes
	x = Po2D.x;
	y = Po2D.y;
	z = 99999.0;
//## end CPoint3D::operator =%967A30B5FEED.body
}
//-- {AddDecl: 576} region.unprotectedFunction [5452..5575]

// offsetting with vector
CPoint3D CPoint3D::operator+(VECTOR3D v) const
{
//## begin CPoint3D::operator +%6A1A55E0FEED.body preserve=yes
	return CPoint3D(x+v.dx,y+v.dy,z+v.dz);
//## end CPoint3D::operator +%6A1A55E0FEED.body
}
//-- {AddDecl: 577} region.unprotectedFunction [5576..5655]

void CPoint3D::operator+=(VECTOR3D v)
{
//## begin CPoint3D::operator +=%71816F14FEED.body preserve=yes
	x+=v.dx;
	y+=v.dy;
	z+=v.dz;
//## end CPoint3D::operator +=%71816F14FEED.body
}
//-- {AddDecl: 578} region.unprotectedFunction [5656..5752]

CPoint3D CPoint3D::operator-(VECTOR3D v) const
{
//## begin CPoint3D::operator -%E3941090FEED.body preserve=yes
	return CPoint3D(x-v.dx,y-v.dy,z-v.dz);
//## end CPoint3D::operator -%E3941090FEED.body
}
//-- {AddDecl: 579} region.unprotectedFunction [5753..5832]

void CPoint3D::operator-=(VECTOR3D v)
{
//## begin CPoint3D::operator -=%4459E9C8FEED.body preserve=yes
	x-=v.dx;
	y-=v.dy;
	z-=v.dz;
//## end CPoint3D::operator -=%4459E9C8FEED.body
}
//-- {AddDecl: 580} region.unprotectedFunction [5833..5969]


// derive vector = this point - sp
CVector3D CPoint3D::operator-(POINT3D sp) const
{
//## begin CPoint3D::operator -%FE5107CAFEED.body preserve=yes
	return CVector3D(x-sp.x,y-sp.y,z-sp.z);
//## end CPoint3D::operator -%FE5107CAFEED.body
}
//-- {AddDecl: 581} region.unprotectedFunction [5970..6142]

BOOL CPoint3D::operator==(POINT3D pos) const
{
//## begin CPoint3D::operator ==%801381C1FEED.body preserve=yes
	CVector3D  vect(x-pos.x,y-pos.y,z-pos.z);

	if( IS_ZERO( vect.GetLength( ) ) ) return TRUE;
	else return FALSE;

//## end CPoint3D::operator ==%801381C1FEED.body
}
//-- {AddDecl: 582} region.unprotectedFunction [6143..6311]
BOOL CPoint3D::operator!=(POINT3D pos) const
{
//## begin CPoint3D::operator !=%061D63E9FEED.body preserve=yes
	CVector3D  vect(x-pos.x,y-pos.y,z-pos.z);

	if( IS_ZERO( vect.GetLength( ) ) ) return FALSE;
	else return TRUE;
//## end CPoint3D::operator !=%061D63E9FEED.body
}
//-- {InsertRegion: 694} module.vulnerableDeclarations [6312..6665]
//## begin module.additionalDeclarations preserve=yes


/************************************************************************************
/	
/	CLASS NAME:  CVector3D
/   DESCRIPTION: designed for 3 dimensional vector
/   CREATED BY: Olive Wang in Apr.28,2000
/   MODIFIED By:
/
************************************************************************************/
// constructor&&destructor
//## end module.additionalDeclarations
//-- {AddDecl: 583} region.unprotectedFunction [6666..6723]
CVector3D::CVector3D()

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -