📄 cadbase.cpp
字号:
for (i = 0; i < R; i ++)
{
if (i != k)
m.A[i][k] *= -m.A[k][k];
}
}
for (k = R-1; k >= 0; k --)
{
if (js[k] != k)
{
swap(m.A[k][0], m.A[js[k]][0]);
swap(m.A[k][1], m.A[js[k]][1]);
swap(m.A[k][2], m.A[js[k]][2]);
}
if (is[k] != k)
{
swap(m.A[0][k], m.A[0][is[k]]);
swap(m.A[1][k], m.A[1][is[k]]);
swap(m.A[2][k], m.A[2][is[k]]);
}
}
mOut = m;
return fDet * f;
}
//## end module.additionalDeclarations
//-- {AddDecl: 622} region.unprotectedFunction [14315..15443]
CMatrix2D CMatrix2D::operator ~()
//求逆矩阵
{
//## begin CMatrix2D::operator ~%5B71AB1FFEED.body preserve=yes
CMatrix2D mout;
Inverse(mout,*this);
return mout;
// double a[R][R*2];
// double b1[R][R];
// double tt,tt2;
// int i,j,k;
// for( i = 0 ; i < R ; i ++)
// for( j = 0 ; j < R ; j ++ )
// {
// a[i][j]=A[i][j];
// }
// for(i=0;i<=(R-1);i++)
// {
// a[i][i+R]=1;
// }
//
// /********************/
// for(i=0;i<=(R-1);i++)
// for(j=0;j<=(R-1);j++)
// {
// b1[i][j]=a[i][j];
// }
// /**********************/
// for(j=0;j<=(R-1);j++)
// {
// let(j,a);
// for(i=0;i<=(R-1);i++)
// {
// if((a[i][j]!=0)&&(i!=j))
// {
// tt2=a[i][j]/a[j][j];
//
// for(k=0;k<=(2*R-1);k++)
// {
// a[i][k]=(a[i][k]-(a[j][k]*tt2));
// if(a[i][k]*a[i][k]<0.00001)
// {
// a[i][k]=0;
// }
// }
// }
// }
// }
//
//
// for(i=0;i<=(R-1);i++)
// {
// tt=a[i][i];
// for(j=0;j<=(2*R-1);j++)
// {
// a[i][j]=a[i][j]/tt;
// }
// }
// CMatrix2D ma;
// for(i=0;i<R;i++)
// {
// for(j=R;j<R;j++)
// {
// ma.A[i][j] = a[i][j];
// }
// }
// return ma;
//## end CMatrix2D::operator ~%5B71AB1FFEED.body
}
//-- {AddDecl: 623} region.unprotectedFunction [15444..15622]
CMatrix2D CMatrix2D::T()const
//求转置矩阵
{
//## begin CMatrix2D::T%CBC9FC61FEED.body preserve=yes
CMatrix2D temp;
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
temp.A[j][i]=A[i][j];
}
}
return temp;
//## end CMatrix2D::T%CBC9FC61FEED.body
}
//-- {InsertRegion: 696} module.vulnerableDeclarations [15623..15978]
//## begin module.additionalDeclarations preserve=yes
/************************************************************************************
/
/ CLASS NAME: CMatrix3D
/ DESCRIPTION: designed for 3 dimensional matrix
/ CREATED BY: Olive Wang in Apr.28,2000
/ MODIFIED By:
/
************************************************************************************/
//construction&&destruction
//## end module.additionalDeclarations
//-- {AddDecl: 624} region.unprotectedFunction [15979..16093]
CMatrix3D::CMatrix3D()
{
//## begin CMatrix3D::CMatrix3D%DA5CC5BDFEED.body preserve=yes
for(int i=0;i<4;i++)
for(int j=0;j<4;j++)
{
A[i][j] = (i==j)?1.0:0.0;
}
//## end CMatrix3D::CMatrix3D%DA5CC5BDFEED.body
}
//-- {AddDecl: 625} region.unprotectedFunction [16094..16234]
CMatrix3D::CMatrix3D(const MATRIX3D& matrix)
{
//## begin CMatrix3D::CMatrix3D%D8BBE70AFEED.body preserve=yes
for(int i=0;i<4;i++)
for(int j=0;j<4;j++)
{
A[i][j] = matrix.A[i][j];
}
//## end CMatrix3D::CMatrix3D%D8BBE70AFEED.body
}
//-- {AddDecl: 626} region.unprotectedFunction [16235..16372]
CMatrix3D::CMatrix3D(const double *matrix)
{
//## begin CMatrix3D::CMatrix3D%D275A987FEED.body preserve=yes
for(int i=0;i<4;i++)
for(int j=0;j<4;j++)
{
A[i][j] = matrix[i*4+j];
}
//## end CMatrix3D::CMatrix3D%D275A987FEED.body
}
//-- {AddDecl: 627} region.unprotectedFunction [16373..16405]
CMatrix3D::~CMatrix3D()
{
//## begin CMatrix3D::~CMatrix3D%B6380277FEED.body preserve=yes
//## end CMatrix3D::~CMatrix3D%B6380277FEED.body
}
//-- {AddDecl: 628} region.unprotectedFunction [16406..16728]
//operators
CMatrix3D CMatrix3D::operator*(const MATRIX3D& matrix2) const
{
//## begin CMatrix3D::operator *%32CFC041FEED.body preserve=yes
CMatrix3D matrix;
for(int i=0;i<4;i++)
for(int j=0;j<4;j++){
matrix.A[i][j] = A[i][0]*matrix2.A[0][j]
+ A[i][1]*matrix2.A[1][j]
+ A[i][2]*matrix2.A[2][j]
+ A[i][3]*matrix2.A[3][j];
}
return matrix;
//## end CMatrix3D::operator *%32CFC041FEED.body
}
//-- {AddDecl: 629} region.unprotectedFunction [16729..16816]
void CMatrix3D::operator*=(const MATRIX3D& matrix)
{
//## begin CMatrix3D::operator *=%C25B034CFEED.body preserve=yes
(*this) = (*this)*matrix;
//## end CMatrix3D::operator *=%C25B034CFEED.body
}
//-- {AddDecl: 630} region.unprotectedFunction [16817..16953]
//methods
void CMatrix3D::IdenticalMatrix()
{
//## begin CMatrix3D::IdenticalMatrix%36C99EFBFEED.body preserve=yes
for(int i=0;i<4;i++)
for(int j=0;j<4;j++)
{
A[i][j] = (i==j)?1.0:0.0;
}
//## end CMatrix3D::IdenticalMatrix%36C99EFBFEED.body
}
//-- {AddDecl: 631} region.unprotectedFunction [16954..17182]
double CMatrix3D::GetValue() const
{
//## begin CMatrix3D::GetValue%FEDFF24DFEED.body preserve=yes
return A[0][0]*A[1][1]*A[2][2] +
A[0][1]*A[1][2]*A[2][0] +
A[0][2]*A[1][0]*A[2][1] -
A[0][2]*A[1][1]*A[2][0] -
A[0][1]*A[1][0]*A[2][2] -
A[0][0]*A[1][2]*A[2][1];
//## end CMatrix3D::GetValue%FEDFF24DFEED.body
}
//-- {AddDecl: 632} region.unprotectedFunction [17183..17511]
// static member functions
double CMatrix3D::GetValue(double a00, double a01, double a02,
double a10, double a11, double a12,
double a20, double a21, double a22)
{
//## begin CMatrix3D::GetValue%A65983EBFEED.body preserve=yes
return a00*a11*a22 +
a01*a12*a20 +
a02*a10*a21 -
a02*a11*a20 -
a01*a10*a22 -
a00*a12*a21;
//## end CMatrix3D::GetValue%A65983EBFEED.body
}
//-- {AddDecl: 633} region.unprotectedFunction [17512..17962]
CMatrix3D CMatrix3D::CreateMirrorMatrix(VECTOR3D v)
{
//## begin CMatrix3D::CreateMirrorMatrix%A6000DD6FEED.body preserve=yes
double len=((CVector3D)v).GetLength();
CMatrix3D matrix;
matrix.A[0][0]= (v.dx*v.dx -1.0)*2.0/len/len;
matrix.A[1][1]= (v.dy*v.dy -1.0)*2.0/len/len;
matrix.A[2][2]= (v.dz*v.dz -1.0)*2.0/len/len;
matrix.A[0][1]=matrix.A[1][0]= v.dx*v.dy*2.0/len/len;
matrix.A[0][2]=matrix.A[2][0]= v.dx*v.dz*2.0/len/len;
matrix.A[1][2]=matrix.A[2][1]= v.dz*v.dy*2.0/len/len;
return matrix;
//## end CMatrix3D::CreateMirrorMatrix%A6000DD6FEED.body
}
//-- {AddDecl: 634} region.unprotectedFunction [17963..19214]
CMatrix3D CMatrix3D::CreateRotateMatrix(double da,VECTOR3D v)
{
//## begin CMatrix3D::CreateRotateMatrix%2CA34126FEED.body preserve=yes
CMatrix3D Ro;
CVector3D bv(v);
if(IS_ZERO(da)) return Ro;
ASSERT(!bv.IsZeroLength());
double lxy=bv.GetLengthXY();
if(IS_ZERO(lxy))
{
if(bv.dz < 0.0) da *= -1.0;
Ro.A[0][0]=Ro.A[1][1]=cos(da);
Ro.A[0][1]=sin(da);Ro.A[1][0]=-sin(da);
return Ro;
}
double lyz=bv.GetLengthYZ();
if(IS_ZERO(lyz))
{
if(bv.dx < 0.0) da *= -1.0;
Ro.A[2][2]=Ro.A[1][1]=cos(da);
Ro.A[1][2]=sin(da);Ro.A[2][1]= -sin(da);
return Ro;
}
double lxz=bv.GetLengthZX();
if(IS_ZERO(lxz))
{
if(bv.dy < 0.0) da *= -1.0;
Ro.A[0][0]=Ro.A[2][2]=cos(da);
Ro.A[0][2]=-sin(da);Ro.A[2][0]=sin(da);
return Ro;
}
CMatrix3D Rz;
Rz.A[0][0]=Rz.A[1][1]=bv.dy/lxy;
Rz.A[0][1]=bv.dx/lxy;Rz.A[1][0]= -bv.dx/lxy;
double len=bv.GetLength();
CMatrix3D Rx;
Rx.A[2][2]=Rx.A[1][1]=bv.dz/len;
Rx.A[1][2]=lxy/len;Rx.A[2][1]= -lxy/len;
Ro.A[0][0]=Ro.A[1][1]=cos(da);
Ro.A[0][1]=sin(da);Ro.A[1][0]= -sin(da);
CMatrix3D Rxn;
Rxn.A[2][2]=Rxn.A[1][1]=bv.dz/len;
Rxn.A[2][1]=lxy/len;Rxn.A[1][2]= -lxy/len;
CMatrix3D Rzn;
Rzn.A[0][0]=Rzn.A[1][1]=bv.dy/lxy;
Rzn.A[1][0]=bv.dx/lxy;Rzn.A[0][1]= - bv.dx/lxy;
return Rz*Rx*Ro*Rxn*Rzn;
//## end CMatrix3D::CreateRotateMatrix%2CA34126FEED.body
}
//-- {AddDecl: 635} region.unprotectedFunction [19215..19334]
CMatrix3D CMatrix3D::CreateScaleMatrix(double d)
{
//## begin CMatrix3D::CreateScaleMatrix%72A0C822FEED.body preserve=yes
CMatrix3D m;
m.A[0][0]=m.A[1][1]=m.A[2][2]=d;
return m;
//## end CMatrix3D::CreateScaleMatrix%72A0C822FEED.body
}
//-- {AddDecl: 636} region.unprotectedFunction [19335..19484]
CMatrix3D CMatrix3D::CreateTransfMatrix(VECTOR3D vec)
{
//## begin CMatrix3D::CreateTransfMatrix%9201CA48FEED.body preserve=yes
CMatrix3D m;
m.A[3][0]=vec.dx;
m.A[3][1]=vec.dy;
m.A[3][2]=vec.dz;
return m;
//## end CMatrix3D::CreateTransfMatrix%9201CA48FEED.body
}
//-- {AddDecl: 637} region.unprotectedFunction [19485..19767]
////////////////////////////////////////////////////////////////////////////////////
//
// CLASS: CBox2D
//
//
//
/////////////////////////////////////////////////////////////////////////////////////
//constructor && destructor
CBox2D::CBox2D()
{
//## begin CBox2D::CBox2D%5DE082A8FEED.body preserve=yes
x0=y0=x1=y1=0;
//## end CBox2D::CBox2D%5DE082A8FEED.body
}
//-- {AddDecl: 638} region.unprotectedFunction [19768..19887]
CBox2D::CBox2D(double ix0,double iy0,double ix1,double iy1)
{
//## begin CBox2D::CBox2D%53E2F0BFFEED.body preserve=yes
x0 = ix0; y0=iy0; x1=ix1; y1=iy1;
normalize();
//## end CBox2D::CBox2D%53E2F0BFFEED.body
}
//-- {AddDecl: 639} region.unprotectedFunction [19888..19995]
CBox2D::CBox2D(POINT2D pt0,POINT2D pt1)
{
//## begin CBox2D::CBox2D%F4B86D5CFEED.body preserve=yes
x0 = pt0.x; y0=pt0.y; x1=pt1.x; y1=pt1.y;
normalize();
//## end CBox2D::CBox2D%F4B86D5CFEED.body
}
//-- {AddDecl: 640} region.unprotectedFunction [19996..20083]
CBox2D::CBox2D(BOX2D b)
{
//## begin CBox2D::CBox2D%7C0C7A5DFEED.body preserve=yes
x0=b.x0; y0=b.y0;
x1=b.x1; y1=b.y1;
normalize();
//## end CBox2D::CBox2D%7C0C7A5DFEED.body
}
//-- {AddDecl: 641} region.unprotectedFunction [20084..20192]
CBox2D::CBox2D(POINT2D p,VECTOR2D v)
{
//## begin CBox2D::CBox2D%7D83A768FEED.body preserve=yes
x0=p.x; y0=p.y;
x1=p.x+v.dx;
y1=p.x+v.dy;
normalize();
//## end CBox2D::CBox2D%7D83A768FEED.body
}
//-- {AddDecl: 642} region.unprotectedFunction [20193..20219]
CBox2D::~CBox2D()
{
//## begin CBox2D::~CBox2D%9A090FD7FEED.body preserve=yes
//## end CBox2D::~CBox2D%9A090FD7FEED.body
}
//-- {AddDecl: 643} region.unprotectedFunction [20220..20472]
// operator
//// get the union box of this and box b.
CBox2D CBox2D::operator+(BOX2D b) const
{
//## begin CBox2D::operator +%BBFFF5F5FEED.body preserve=yes
CBox2D box;
box.x0 = (x0<b.x0)?x0:b.x0;
box.y0 = (y0<b.y0)?y0:b.y0;
box.x1 = (x1>b.x1)?x1:b.x1;
box.y1 = (y1>b.y1)?y1:b.y1;
return box;
//## end CBox2D::operator +%BBFFF5F5FEED.body
}
//-- {AddDecl: 644} region.unprotectedFunction [20473..20557]
void CBox2D::operator+=(BOX2D b)
{
//## begin CBox2D::operator +=%78A3F5D6FEED.body preserve=yes
CBox2D box = (*this)+b;
(*this) = box;
//## end CBox2D::operator +=%78A3F5D6FEED.body
}
//-- {AddDecl: 645} region.unprotectedFunction [20558..20883]
//// get the intersect box of this and box b.
CBox2D CBox2D::operator&(BOX2D b) const
{
//## begin CBox2D::operator &%625FBE2EFEED.body preserve=yes
CBox2D box;
double xx0,yy0,xx1,yy1;
xx0 = (x0>b.x0)?x0:b.x0;
yy0 = (y0>b.y0)?y0:b.y0;
xx1 = (x1<b.x1)?x1:b.x1;
yy1 = (y1<b.y1)?y1:b.y1;
if((xx1>xx0) && (yy1>yy0)){
box = CBox2D(xx0,yy0,xx1,yy1);
}
return box;
//## end CBox2D::operator &%625FBE2EFEED.body
}
//-- {AddDecl: 646} region.unprotectedFunction [20884..20966]
void CBox2D::operator&=(BOX2D b)
{
//## begin CBox2D::operator &=%AE3FE703FEED.body preserve=yes
CBox2D box = (*this)&b;
*this = box;
//## end CBox2D::operator &=%AE3FE703FEED.body
}
//-- {AddDecl: 647} region.unprotectedFunction [20967..21055]
// get attribs
BOOL CBox2D::IsZero() const
{
//## begin CBox2D::IsZero%DB2B5C39FEED.body preserve=yes
return IS_ZERO(Width()*Height());
//## end CBox2D::IsZero%DB2B5C39FEED.body
}
//-- {AddDecl: 648} region.unprotectedFunction [21056..21134]
double CBox2D::Width() const // Length of X direction
{
//## begin CBox2D::Width%C48F5770FEED.body preserve=yes
return x1-x0;
//## end CBox2D::Width%C48F5770FEED.body
}
//-- {AddDecl: 649} region.unprotectedFunction [21135..21214]
double CBox2D::Height() const // Length of Y direction
{
//## begin CBox2D::Height%2BF16F95FEED.body preserve=yes
return y1-y0;
//## end CBox2D::Height%2BF16F95FEED.body
}
//-- {AddDecl: 650} region.unprotectedFunction [21215..21469]
// relationship culation
// there may be four cases:
// <enumSeparated,enumIntersected>
UINT CBox2D::GetRelationWith(BOX2D b) const
{
//## begin CBox2D::GetRelationWith%C41314E3FEED.body preserve=yes
CBox2D box;
box = (*this)&b;
if(box.IsZero())
return enumSeparated;
else
return enumIntersected;
//## end CBox2D::GetRelationWith%C41314E3FEED.body
}
//-- {AddDecl: 651} region.unprotectedFunction [21470..21663]
void CBox2D::normalize()
{
//## begin CBox2D::normalize%5A9DDBCAFEED.body preserve=yes
double xx0,yy0,xx1,yy1;
xx0 = (x0<x1)?x0:x1;
xx1 = (x0>x1)?x0:x1;
yy0 = (y0<y1)?y0:y1;
yy1 = (y0>y1)?y0:y1;
x0 = xx0; y0 = yy0; x1 = xx1; y1 = yy1;
//## end CBox2D::normalize%5A9DDBCAFEED.body
}
//-- {AddDecl: 652} region.unprotectedFunction [21664..21950]
////////////////////////////////////////////////////////////////////////////////////
//
// CLASS: CBox3D
//
//
//
/////////////////////////////////////////////////////////////////////////////////////
//constructor && destructor
CBox3D::CBox3D()
{
//## begin CBox3D::CBox3D%3DC30564FEED.body preserve=yes
x0=y0=z0=x1=y1=z1=0;
//## end CBox3D::CBox3D%3DC30564FEED.body
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -